hi all,
i am trying to make a prog. which will read the first line of a text file and put the first line into an array and pass the entire array to a function.
Here is my code:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <string.h>
void exe(char cmd)
{
printf("%c",cmd);
}
int main()
{
char st;
FILE *p;
char cmd[8];
p = fopen("test.txt", "rt");
if (p == NULL)
{
printf("File does not exist.\n");
}
else
{
while(1)
{
int i;
st = fgetc(p);
if (st == '\n')
break;
else
cmd[i]= st;
i++;
}
}
fclose(p);
exe(cmd);
return 0;
}
But the code is not working.Can any one please suggest .