how to print the first character in a string using strtok
I need help with a program to pull the first character out of a string I read in. I'm using strtok to get the first name and last name separated by a pipe " | " here is my while loop.
while (fgets(buffer,100,stin) != NULL) { token[0] = strtok(string, " | "); // gets the first name token[1] = strtok(NULL, " | "); // gets the last name Basically I need to print out the first initial and last name ..... Any ideas???? |
If you're sure the pipe will be there I'd just do this:
Code:
printf("%c %s\n", string[0], strchr(string, '|')+1); |
Thats not going to work the name comes in like this -----> Bob|Smith|
I need to be able to print BSmith. I need to find out if the strok will let me somehow pull the first char out of token[0] which is the first name = Bob. |
Can anyone else give some input????
|
Here's a couple of different ways to do it:
Code:
#include <stdio.h> Code:
#include <stdio.h> |
Thanks for your help I know have it up and running :D :D :D
|
All times are GMT -5. The time now is 05:54 AM. |