Why in doesn't work?

I need read file per line, but my bicycle doesn't make it.
How to read too long string and optimal to use it of memory?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  FILE * pFile;
  long lSize;
  char * buffer;
  long * command;
  int rn, i =0,m = 0;
  pFile = fopen ("myfile.txt","rb");
  fseek(pFile,0,SEEK_END);
  lSize = ftell (pFile);
  fseek(pFile,0,SEEK_SET);
  buffer = (char*) malloc (sizeof(char)*siz);
  if (pFile==NULL) perror ("Error opening file");
  else{
  fread(buffer,1,lSize,pFile);
  for (; i < lSize; ++i){
    if ('\n' == buffer[i]){
        rn++;
        }else
        if ('\r' == buffer[i]);
        else
        rn = 0;
        if (10 == rn){
        strcmp(buffer,command,sizeof(buffer));
        }
    printf("%s",command );
    fclose (pFile);
    }//for
  return 0;
  }
Last edited on
Do you need to use the C method of file I/O?

Otherwise, I'd use an fstream and use the getline() function.
Topic archived. No new replies allowed.