I really hope I'm not doing your homework for you.
(changes in red)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DELIM " "
int main(int argc, char *argv[])
{
FILE *in, *out;
char buf[BUFSIZ];
char tmp[100];
char * place;
int column = 2; //this is the number of the column where employee name is stored, 2 was just my test value
int i, j;
if ( (in = fopen( "emp.txt", "r")) == NULL )
{
printf("Could not open file.");
exit(1);
}
for ( i = 0; (fgets( buf, BUFSIZ, in )) != NULL; i++ )
{
place = strtok( buf, DELIM );
for ( j = 1; j < column; j++ )
{
place = strtok( NULL, DELIM );
}
sscanf( place, "%s", tmp);
printf("%s\n", tmp);
}
system("PAUSE");
return 0;
}
Again, ignore or change the system pause for your system. Yes, I know I should change, I'll do it soon. And this code probably isn't rock solid, it's just the bare essentials to get the job done.