how to put fgets into an array??

Hey guys i'm really new to programming so it'll be great if you guys can explain it as simple as you could.

so my problem is im trying to put a pair of input strings into arrays but i can't figure out the best way to do it.

basically,

i = 0;
j = 1;
while(i < MAX_RULES && fgets(rule, MAX_STRING, stdin) != NULL){
}
while(j < MAX_RULES && fgets(rule, MAX_STRING, stdin) != NULL){
}
i += 2;
j += 2;

i know this is probably isn't right but i don't know how to fix it :/

and i also need to print it like
rule[0] = rule[1]
rule[2] = rule[3]
rule[4] = rule[5]

thanks for the help!!
fgets works with C FILE*s so my first question is are you trying to write this in C or C++?

- Why do you have two indexes i and j, when you have only a 1D array? (note: j will always be i+1)
- Same question goes for your pair of while loops.
- What exactly are you trying to do here?

PS: You need to declare i and j as ints, but I'll assume you just omitted that part...
im writing this in C.

I want to have an input that reads in a "rule" in array 0 and then the expansion of that rule in array 1
they would be sort of pair cause i need to relate the rule to the expansion later on.

example: rule[0] = F
rule[1] = F + f

and this goes on with more rules so i was thinking the rules could be even numbers while the expansion could be odd numbers.

ps: yeah i omitted the declaration parts
I'm still not getting it. Can you give an example file, and program output (or logic?)
i dont think i have an example file but i'll try to explain the logic

I'm asked to put in sets of "rules" that comes in two lines. How it's supposed to go is that i have to type in the first line which is one letter. the next line would be sort of what the letter would expand to.

example:

F
F+F
a
c+b

so as you can see
F would represent the string F+F
while a is the string c+b

this would be later used when i type in a string such as "F+aF" which is supposed to use the rules to expand itself. i hope i explained it well enough.
Topic archived. No new replies allowed.