Hello adak and pytony! :)

thank you! I was able to solve that problem by getting a counter.

but now,i got another problem. I stored the result of comparing in adjacency list and now i want to group together rows that doesn't have a word in common.

Any ideas on how to do that? I tried if else but at the end random numbers popped out :(

Please help me. thank you very much :)


But the problem is that this array[row][0] doesn't just contain the word CAT but it contains lots of random characters :( Even though I restricted my array to be array[row][n][3]

Thank you Adak! I will try to do that :)

[QUOTE=Adak;1593068]Generally speaking (since I don't know the specifics of what you're trying to do), you want to have one word per line, in a two dimension array.

The key is the separator between the words (a space), and the newline separates the last word in the line, and the line itself, (both).

A file for reading input would never be set to append mode "a". There's nothing at that end of the file to be read! Just open it for reading, instead.

If you REALLY want to read in three words at a time, and put them into one row of a 2D char array, then you can easily do it by using fgets().

It can happen that some words will not be full strings in C, because they just don't have an end of string marker right after their last letter: '\0'. Even though you can't see this char, it's important for working with strings, as strings. (that is, using the string functions).[/QUOTE]

Hello adak! i actually want to do it this way:
array[line_number][word_number] = word

I was able to do that already, but i did it this way:
array[line_number][word_number][i] = ith letter of the word
i did this to be able to determine if a new word is encountered.
but what happened was:
array[line_number][word_number][20] = 'a' //or some other letter, though my limit for that counter is 3, typing in 20 would give letters :( which I find impossible because I have a line that goes like this: ...

[QUOTE=pyTony;1592989]So you are looping your [B]output[/B].txt with [B]i[/B]fp looks illogical naming. Why 'a' mode for ofp? (which is never used)
Why lines 11 to 14 and at least why a<20 and b<20 and line 9 says char data[8][8][3]?[/QUOTE]

Hi PyTony! :) Thank you for that! I made a for ofp because we need to produce an output file that would contain the compared words.

Hello guys! i really need your help.

In my program, I am reading the contents of the file.

File looks like this:


I want to store the words in an array. one array per line.

I just would like to ask how do you separate the number from the words when reading from the file? And how will the computer know that it is already going to a new line, thus must fill the next array. Knowing when the next line starts troubles me because each line could have any number of words, max of 8 words per line.

I have been thinking of these for the past three days,

and so far this is what I got,
i know this is short but with this code, I already get a segmentation fault. i don't know why.

Please, help me.

int main() {

FILE *ifp, *ofp;

ofp = fopen("input.txt", "a");

ifp = fopen("output.txt", "r");

char data[8][8][3];
int a,b,z;
for (a=0; a<20; a++)
    for (b=0;b<20; b++)
        for (z=0; z<3; z++)
            data[a][b][z] = ' '; 

char number[20];

char c;

while ((c = getc(ifp)) != EOF) {
printf(c); // i did this to check if it is successful reading


please shed some light. thank you very much.