hi,
im just simply copying the whole contents of a file from the net into a string in my program and printing it out...this doesnt work,,any suggestions on how to fix or do it another way?
Code:
FILE *p;
char *file = NULL;
long fileSize = 0;
if((p = popen("/usr/other/sdm/Bin/wget -q -O - http://homepages.ihug.com.au/~pooni/xml/test.xml","r")) == NULL) {
fprintf(stderr, "cannot create pipe \n");
exit(1);
}
fseek(p, 0, SEEK_END);
fileSize = ftell(p);
rewind(p);
if (fileSize < 1){
fprintf(stderr, "File has no data\n");
exit(1);
}
file = (char *) calloc((fileSize+1), sizeof(char));
if (!file){
fprintf(stderr, "Unable to allocate %d bytes of memory\n", fileSize);
exit(1);
}
fread(file, fileSize, 1, p);
file[fileSize] = '\0';
printf("File is %ld bytes. File Data:\n%s\n", fileSize, file);
free(file);
fclose(p);