i am trying to build a simple c that reads a file and enters in into a string, but i am getting this error while compiling:
try.c:8: error: incompatible types in initialization
this is the code:
#include <stdlib.h>
#include <stdio.h>
int main()
{
FILE *try = fopen("C:\\Users\\User\\Desktop\\try1.txt", "r");
char *string = *try;
printf("%s\n", string);
printf("%s\n", try);
system("PAUSE");
return 0;
}
how can i fix this? thanks
*try
isFILE
, notchar *
, of course. You wantfread()
orfgets()
or something. – Tavian Barnes Feb 18 '16 at 15:41char *string = NULL; size_t bufsize = 0; ssize_t slen = getline(&string, &bufsize, try);
– EOF Feb 18 '16 at 15:42fgets
orfscanf
. – ameyCU Feb 18 '16 at 15:43getline
is not standard. Usefgets
instead. – too honest for this site Feb 18 '16 at 15:46getline()
is POSIX. If you don't havegetline()
, I'm terribly sorry for you. – EOF Feb 18 '16 at 15:48