hi,
Lets say I have format: FN MI LN
Now..how do I initialize the space after MI to '\0' in a loop for varying lengths of FN MI LN..
Btw..FN is First name..MI is middle initial..& LN is Last Name..
Please Help.
A
hi,
Lets say I have format: FN MI LN
Now..how do I initialize the space after MI to '\0' in a loop for varying lengths of FN MI LN..
Btw..FN is First name..MI is middle initial..& LN is Last Name..
Please Help.
A
I don't understand. Could you try again?
You could loop through the string and keep a int that gives you the position. If that position String[Pos] is a space then set it equal to a '\0'.
- SeanCode:while(Pos<strlen(String){ if(String[Pos]=='\0';){ String[Pos] = '\0'; } Pos++; }
If cities were built like software is built, the first woodpecker to come along would level civilization.
Black Frog Studios
I presume you mean something like this:Originally posted by aspand
hi,
Lets say I have format: FN MI LN
Now..how do I initialize the space after MI to '\0' in a loop for varying lengths of FN MI LN..
Btw..FN is First name..MI is middle initial..& LN is Last Name..
Please Help.
A
Code:#include <stdio.h> #include <string.h> int main(void) { char name[] = "Eric T Cartman"; char *ptr; printf ("Name is currently: %s\n", name); if ((ptr = strrchr(name, ' ')) != NULL) *ptr = '\0'; printf ("Name is now: %s\n", name); return (0); } /* Program output: Name is currently: Eric T Cartman Name is now: Eric T */
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]