1234
1234
Last edited by loso44x; 10-02-2005 at 06:52 PM.
edit: gah i keep doing that, also removed quotes around zero.Code:#include <string.h> ... ... ... char* p = strchr(string,'\n'); if (p) *p = 0;
thanks, quzah
Last edited by nonpuz; 10-01-2005 at 08:39 PM.
Minor error there. Compile that, and see what your compiler has to say.Originally Posted by nonpuz
Quzah.
Hope is the first step on the road to disappointment.
i edited the code to thisbut i get the same results am i doing something wrong?Code:for (i=0;i<=SIZE;i++) { fscanf(in_file, "%35[^,],%10[^,],%10[^,],%s",movies[i].title, movies[i].rating,movies[i].date,&movies[i].length); char* p = strchr(movies[i].length,'\n'); if (p) *p = 0; printf("Name of Movie:%s \n Rating:%s \n Date:%s \n Length:%s\n",movies[i].title, movies[i].rating,movies[i].date,movies[i].length); }
Code:for(j=k+1;j<=SIZE;j++) // j = k + 1 would make it skip anything above it, if e.g. k = 5 or something then it will skip 0 to 4. J should start with 0. { if(strcmp(movies[k].title,movies[j].title) > 0) { movies2=movies[k]; movies[k]=movies[j]; movies[j]=movies2; } }
Originally Posted by loko
i changed j to 0 and it didnt sort.. i think changing it will just compare the same array
4567
Last edited by loso44x; 10-02-2005 at 06:52 PM.
The SIZE of array is only 4 and you have 5 record in there.
k i edited the code but there seems to be a problem with the sortingOriginally Posted by loko
>>printf("%s - %s - %s - %s",movies[k].title,movies[k].rating,movies[k].date,movies[k].length);
This doesn't output any newline characters, you need a \n at the end of each line (I assume). Same for the other printf() statement too.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
if i put a \n after each printf then some will have double space and some will have one spaceOriginally Posted by Hammer
You have a '\n' in the beggining of evry movie title except for the first move in the file.
*edited
try
Code:for (i=0;i<SIZE;i++) { fscanf(in_file, "\n%35[^,],%10[^,],%10[^,],%3[^\n]",movies[i].title, movies[i].rating,movies[i].date,&movies[i].length); }
Last edited by loko; 10-02-2005 at 05:55 PM.
I expect that's what you get for using fscanf() I'm afraid. Unwanted data is being left in the buffer and confusing subsequent calls to fscanf().
Try replacing the call to fscanf() with fgets(), followed by sscanf().
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
thx works like a charm nowOriginally Posted by loko