Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /*
- * fscanf This function returns the number of input items successfully
- * matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure
- *
- *
- * long int ftell ( FILE * stream );
- Get current position in stream
- Returns the current value of the position indicator of the stream.
- For binary streams, this is the number of bytes from the beginning of the file.
- For text streams, the numerical value may not be meaningful but can still
- be used to restore the position to the same position later using fseek (if there are characters put
- back using ungetc still pending of being read, the behavior is undefined).
- *
- *
- *
- * char * fgets ( char * str, int num, FILE * stream );
- Get string from stream
- Reads characters from stream and stores them as a C string into str until (num-1)
- characters have been read or either a newline or the end-of-file is reached, whichever happens first.
- A newline character makes fgets stop reading, but it is considered a valid character by the function and included in the string copied to str.
- *
- *
- * On success, the function returns str.
- If the end-of-file is encountered while attempting to read a character, the eof indicator is set (feof).
- If this happens before any characters could be read, the pointer returned is a null pointer (and the contents of str remain unchanged).
- If a read error occurs, the error indicator (ferror) is set and a null pointer is also returned (but the contents pointed by str may have changed).
- *
- */
- #define MAX_LEN 500
- int main() {
- FILE*f;
- f = fopen("../in.txt", "r");
- if (f == NULL){
- return 66;
- }
- int n=100;
- char *tab[1000];
- // fscanf(f, "%d", &n1);
- // fscanf(f, "%d", &n2);
- // printf("%d\n", n);
- int index_citit = 0;
- int nr_potriviri = 0;
- while(feof(f) == 0){
- tab[index_citit] = (char*)malloc(sizeof(char) * MAX_LEN);
- char*ret = fgets(tab[index_citit], MAX_LEN, f);
- index_citit++;
- }
- printf("\n%s\n", tab[2]);
- fclose(f);
- for (int i=0; i< index_citit;i++)
- free(tab[i]);
- return 0;
- }
RAW Paste Data