whats wrong here?

This is a discussion on whats wrong here? within the C++ Programming forums, part of the General Programming Boards category; It only returns the first line of the text file over and over again. Why? Code: //read a file. FILE ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    whats wrong here?

    It only returns the first line of the text file over and over again. Why?
    Code:
    					//read a file.
    					FILE *t;
    					 long lSize;
    					char * buffer;
    					char *l;
    					int i = 0;
    					//read a file.
    					t = fopen("test.txt","rb");
    					if (t!=NULL) {
    						fseek (t , 0 , SEEK_END);
    						lSize = ftell (t);
    						rewind (t);
    						buffer = (char*) malloc (lSize);
    						fread (buffer,1,lSize,t);
    						l = strtok(buffer,"\r\n");
    						while(l != NULL) { 
    							if (strlen(l)>0) {
    								dccfsend(cSock,"%s\r\n",buffer);
    								l = strtok(NULL,"\r\n");
    							}
    						}
    						fclose(t);
    						free (buffer);
    						remove( "test.txt" );
    					} else dccfsend(cSock,"File Not Found: %s\r\n", arg);

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I think that it might be here. Kind of subtle

    Code:
    						l = strtok(buffer,"\r\n");
    						while(l != NULL) { 
    							if (strlen(l)>0) {
    								dccfsend(cSock,"%s\r\n",buffer);
    								l = strtok(NULL,"\r\n");
    							}
    						}
    The second parameter is a set of all the delimiters, not a string that can be used as a delimiter.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    71
    Quote Originally Posted by Tonto
    I think that it might be here. Kind of subtle

    Code:
    						l = strtok(buffer,"\r\n");
    						while(l != NULL) { 
    							if (strlen(l)>0) {
    								dccfsend(cSock,"%s\r\n",buffer);
    								l = strtok(NULL,"\r\n");
    							}
    						}
    The second parameter is a set of all the delimiters, not a string that can be used as a delimiter.
    Thank, it was here
    dccfsend(cSock,"%s\r\n",buffer);
    not buffer but l it should be.

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Yeah, that makes more sense.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21