I have a string , let's say a="!_30".
I have another string to , let's say b="cool++".
I wanna replace string a value with cool.
I wanna a="cool" , without those 2 pluses.
How can I do it , with some C string function. Not vith array's or pointer's ?
I mean , I want , a be cool , in place of !_30.
I made it to replace totaly a with b , but I wanna replace totaly a with only one portion of b ..
result :
a = not working
a = coolworking
b = cool++
The thing is , that I wanted , a become a="cool" , not a become "coolworking" .. totaly replace.In my first example strlen(!_30)==strlen(cool) .. my bad ..
P.S. : I hate C , on string processing ..
I made something , like , and it's working like I want ( maybe some users need this idea ).
#include <stdio.h>
#include <string.h>
int
main()
{
char a[]="now is working";
char b[]="cool++";
char bug[256];
int g;
printf("a = %s \n",a);
for (g=0;g<strlen(b)-2;g++)
{ bug[g]=b[g]; }
bug[g]='\0';
stpcpy(a,bug);
printf("a = %s \n",a);
exit(0);
}
Let's say I have this string s="send !_30 <what I wanna send>".
It's there a C fucntion ( in strings ) , I can use to copy !_30 in another string.
I mean , a C function to copy a string beginning from position x and ending in position y from string s.
Let's say : s="send !_30 <what I wanna send>"
012345678
something like this : copy from position 5 to postion 8 , to string s1 meaning s1="!_30"
By the way : Does it exist a function , I can use to see if 2 C string's are identical ?
P.S. : I made it to copy that string ... but I'm still curios if I can do it easier with a function ...
can you copy given number of chars from one string to another - starting from a position chosen by you
can you compare two strings
#include<stdio.h>
#include<string.h>
int main() {
char s[]="send !_30 <what I wanna send>";
char s1[10];
char s2[]="tesT";
char s3[]="tesT";
/* strncpy to copy strings */
strncpy(s1,s+5,4);
fprintf(stdout,"%s\n",s1);
if(strcmp(s2,s3)==0) {
fprintf(stdout,"strings are identical...\n");
}
}
Note that you cannot specify directly to the function the starting position of the string. You have to use something like s+5 to move to the start position of the copy.