Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Reading a file */
- #include <stdio.h>
- #include <stdlib.h>
- int main() {
- // FILE
- FILE *mainfile;
- mainfile = fopen("file.txt", "r");
- if (!mainfile) { system("pause"); return(0); }
- // end FILE
- // VARIABLES
- int qnt /* line breaks */, brli = 10 /* to add to string with realloc */;
- int f, f2; /* any use */
- //end VARIABLES
- // MALLOC
- unsigned char *string[brli];
- string = (unsigned char *) malloc(10000 * sizeof(char)); /* Compiler: incompatible types in assignment */
- if (!string) { system("pause"); return(0); }
- // end MALLOC
- for (qnt = 0; qnt < 9999; qnt++) { // to each record
- fgets(string[qnt], 9999, mainfile); // get the record
- // FREE
- for (f = 0; f < 9999; f++) { // each byte
- if (string[qnt][f] == '\0') { // if byte = line break:
- while (f < 9999) { // while byte isn't the end of the record
- f++; // next byte
- free(string[qnt][f]); /* (freeing byte) Compiler: [Warning] passing arg 1 of `free' makes pointer from integer without a cast */
- } // freeing all bytes until the end of the record
- }
- } // release all unused bytes
- // end FREE
- // REALLOC
- if (qnt == (brli - 1)) { // if have more line breaks than the last allocation or re-allocation:
- brli += 10; // adding more 10 possibles line breaks
- unsigned char *newstr[brli];
- newstr = realloc(string, brli * sizeof(int)); /* Compiler: incompatible types in assignment */
- if (!newstr) { system("pause"); return(0); }
- string = newstr; /* Compiler: incompatible types in assignment */
- }
- // end REALLOC
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement