lol allready stuck again thanks master was helpful.
I need a function to count the number of rows in a 2 coloumb table and have no idea how I'm going to do it would again, appreciate the help.
Printable View
lol allready stuck again thanks master was helpful.
I need a function to count the number of rows in a 2 coloumb table and have no idea how I'm going to do it would again, appreciate the help.
i probly should make a new thread for this. so i will
Example:
Code:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* This is only a sample to get you started. */
int readDB(FILE *file)
{
int line = 0;
char buffer[256];
int x, y; // since I don't know the nature of your columns...
while(!feof(file))
{
if(fgets(buffer, 256, file))
{
// for good measure, # denote a comment... be creative
if(*buffer != '#')
++line;
else
{
sscanf(buffer, "%d %d", &x, &y);
printf("%04d (%d, %d), line, x, y);
}
}
}
return line;
}
int main(void)
{
char fileName[256];
FILE *banana;
fgets(fileName, sizeof(fileName), stdin);
strtok(fileName, "\n");
if (strstr(fileName, ".dat") != 0)
{
printf("Yes, fileName is *.dat, now you can do stuff");
banana = fopen(fileName, "rb");
if(banana)
{
// do stuff here.
readDB(banana);
fclose(banana);
}
}
return 0;
}
better looks:Code:while(!feof(file))
{
if(fgets(buffer, 256, file))
otherwise - if fgets failed due to some error that does not signals eof condition - you'll get the infinite loopCode:while(fgets(buffer, sizeof buffer, file))