Is it possible to read dat files into a struct and if so how the heck do we do that??? Oh and then I need to take the struct and turn it into a node.....
Printable View
Is it possible to read dat files into a struct and if so how the heck do we do that??? Oh and then I need to take the struct and turn it into a node.....
http://groups.google.com/groups/sear...+c&qt_s=Search
http://groups.google.com/groups/sear...ct&qt_s=Search
Do or do not, there is no try. But um. In your case, you should really try, because yr whiny.
Maybe, but at least I'm self aware.... That helped a little....I'm working in C trying to read a dat. file into a struct....if I wasn't clear before.
Tonto...your a sad and lonely person aren't you??? If you ever need to talk about all that anger....I suppose I could make some time.......
>> Maybe, but at least I'm self aware
Zing! Where'd you come up with that one? Ego tripping? LSD tripping? Brushing your teeth? Have an identity crisis and lie to yourself to to rationalize the fact that you're wrong?
>> I'm working in C trying to read a dat. file into a struct....if I wasn't clear before.
I posted links demonstrating techniques to read a structure from a file, and you want to read a file into a structure. Are you saying that I didn't get that? Those are exactly the same things! It doesn't make much sense to read one a file into a structure and then make an isolated node with it, but I suppose if there was a chain of such files it could make sense.
Well post what you've tried, and what you've managed to determine "isn't working".
Assuming you got the structure right, and the reading right, there is no reason why it wouldn't work.
I haven't tried anything yet. I've just never encountered it. I don't necessarily need an answer as much as I just need to see some prototypes or even just pseudo-code.
Basically I have a dat file with lines like this: XXXX XXXXX XXXXXX XXXXXX
I need to shove that data in my struct....I could just read it in, what I do not know is how to split it up. The only thing I've done is stuff like this:
Code:#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define SIZE 63
#define LBUFSIZE 64
int getWord(FILE *fp, char wbuf[], int c);
void output(FILE *csis, char lbuf[]);
FILE *fp;
FILE *csis;
void main(void)
{
csis = fopen("csis.dat", "w");
fp = fopen("getty.dat", "r");
int c = 0;
char wbuf[SIZE];
char lbuf[LBUFSIZE];
lbuf[0] = '\0';
c = getWord(fp, wbuf, c);
while(c != EOF)
{
//add 1 for space
if((strlen(lbuf) + 1 + strlen(wbuf)) > 62)
{
output(lbuf);
strcpy(lbuf, wbuf);
}
else
{
//enough space for this word
strcat(lbuf, " ");
strcat(lbuf, wbuf);
}
c = getWord(fp, wbuf, c);
}
if (c == EOF && strlen(lbuf) > 0)
{
output(csis, lbuf);
}
fclose(fp);
fclose(csis);
}
int getWord(FILE *fp, char wbuf[], int c)
{
int i = 0;
if(isalpha(c))
{
wbuf[i] = c;
i++;
}
c = fgetc(fp);
while(c !=EOF && isalpha(c))
{
wbuf[i] = c;
i++;
c = fgetc(fp);
}
wbuf[i] = '\0';
while(c != EOF && !isalpha(c))
{
c = fgetc(fp);
}
return c;
}
void output(FILE *csis, char lbuf[])
{
printf("%s\n", lbuf);
fprintf(csis, "%s\n", lbuf);
}
Which just reads in a file and then writes it out again.....so that's my sad limited knowledge...
oh and here's what my struct looks like:(probably got that wrong too)
pretty simpleCode:typedef struct employee
{
char fname[10];
char lname[15];
char gender;
int tenure;
char rate;
float salary;
} *PEOPLE
Ok, so you want to get a line using fgets(). After that, you want to seperate it using sscanf.
And your structure looks fine. You just have to get the fgets and sscanf stuff going.
Not void main (void), int main (void).
That void main(void) was for something else......
What for?
seriously man, get over it.Quote:
Originally Posted by manutd
ignoring the question he asked and criticizing something as trivial as his coding style doesn't accomplish anything except make you look condescending, arrogant, and generally unhelpful.
I meant it was for that program example I put above....not the one I'm working on right now....
I have a simple fgetc(fp) function I use to pull word for word from a file which I couple with an output() function....I think I'll just use that and modify the output function to load the struct and then build a function to load the struct into the node....why I have to put the struct into a node I don't understand....but the assignment is load the struct into a node for a file full of employees and employee info...then run linear linked list operations on it....I think this will work....but for whatever I reason I couldn't wrap my head around the problem at first.....thanks for the input !!!!
It's not a "style". The standard clearly says that it should be int main. While this is not directly related to his question, it is in his code, and to be helpful, I corrected him on it. IMO, correcting people's code is not "condescending", it's useful. That's how you learn. If you need clarification, see the FAQ.Quote:
Originally Posted by codepoet
thanks....I realize that int should be used for main....it just wasn't pertenant so I didn't throw it int here.....but I will from now on....thanks