crying crying gonna die already
crying crying gonna die already
I don't see any tear stains on your post, buddy!
What have you tried with fgets()? Post the code and tell us what your status is with learning fgets().
Normally, I'm pretty good with getting an understanding of where people are from their post, but I've been ROFL so much laffing at the drama queens on the programming forums, lately - you know how funny they can be!
given for example
FILE *flevel;
map *current;
current=first;
fgets(flevel,"%s", current->level.levelinfo);
current->level.levelinfo is my string
so what exactly is going to happen?
Some errors - not much else. Wrong format for fgets(). The file pointer is the third parameter for fgets(), not the first. First is the char array name that will be receiving the row of data. Then the size
When you want to post code:
1) highlight it in the advanced editor of the forum, and click on the # icon in the editors menu bar.
2) indent your code. Look at posts from myself, and other regulars - easy to read, and study.
Poor code that looks like the dog got sick, tends to get skipped.
Wow... all emotional.... Try this...
Assuming current->level.levelinfo is a char*...
Code:int GetString(FILE *file) { char *str, *ptr; char buffer[128]; // read disk fgets(buffer,128,file); // get rid of newline ptr = strchr(buffer, '\n') if (ptr) *ptr = 0; // allocate string space str = malloc((strlen(buffer) +1) * sizeof(char)); // hand over a right-sized string return strcpy(str,buffer); } // in main current->level.levelinfo = GetString(fileptr);
wats strchr is it like strtok?
Code:#include <stdio.h> int main() { // open the text file "fred.txt" for writing FILE *out = fopen("fred.txt", "wt"); // write some text to the file fprintf(out, "Hello Fred!\n"); // close the stream, so all changes to the file are saved fclose(out); // open the file "fred.txt" for reading FILE *in = fopen("fred.txt", "rt"); // read the first line from the file char buffer[100]; fgets(buffer, 20, in); // display what we've just read printf("first line of \"fred.txt\": %s\n", buffer); // close the stream fclose(in); return 0; }