Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
First of all, I apologise if I'm bothering anyone with my incessant "similar" questions, but unfortunately the update to my last question was only accepted after 7 days.
I still have the same problem as before: I want to read a CSV into a linked list. I changed my code since my previous question, so I made another "post".

The whole program consists of 2 parts: in one module I create the linked list and 3 functions: the first:Meg gets the corresponding data and returns a concatenated list type element. The second:Appends an element to the concatenated list (no return value). The third:Helps to unlock the concatenated list.And in main, I import the CSV file using the created functions with more or less success.

When the program runs, it does not print anything, not even the basic stuff(Process returned 0 (0x0) execution time : 0.021 s
Press any key to continue.)

There is the my code:
GitHub - 420bela/import: csv[^]

I haven't set up the accented letters yet, but I don't think that should cause an error.

What I have tried:

This is about my third solution "idea" but so far none of them have worked :(
Posted
Updated 18-Nov-23 0:37am
v2
Comments
Andre Oosthuizen 18-Nov-23 6:43am    
Going into question 4 with same issue should have shown you by now what we require to really help you solve this. You cannot just give a link to a bunch of files and code hoping that we will open these to assist you, most of us do not open unknown links at all.

If we do open and view your files on Github, verry little of us will actually spend the time to read through numerous lines of code to try and see where your app is faulty.

The best way to get a proper answer is to post the code that you have (not all of your code as we will not read through hundreds and thousands lines of code either) where the error occurs, post the actual errors or issue with as much information as possible. That way we can understand and then try and solve it with you.

The quicker you follow this, the quicker you will probably have a solution.

Also be more specific with your issue as "It does not work" does not help us at all or make sense to us.
420bela 18-Nov-23 7:23am    
I understand, but what can you write other than that it doesn't work? I did a "test" to see if the linked list works at all. This code will print the data correctly.#include <stdio.h>
#include <stdlib.h>
#include "bevas.h"

int main()
{


Adatok* adat1 = ujelem(1, "MIZU?", "Aa", "Bb", "Cc", "Dd", 'A', "TORI");
hozzafuz(adat1, ujelem(1, "MIZUss?", "Aab", "Bbc", "Ccd", "Dde", 'B', "TOeRI"));

Adatok* jelen = adat1;
while (jelen != NULL) {
printf("%d, %s, %s, %s, %s, %s, %c, %s\n",
jelen->nehezseg,
jelen->kerdes,
jelen->A,
jelen->B,
jelen->C,
jelen->D,
jelen->valasz,
jelen->kategoria);

jelen = jelen->kovetkezo;
}

// Free the allocated memory
felszabadit(adat1);


return 0;
}
When I want to read from a file, it doesn't work (printf doesn't print anything) and probably doesn't include it in the list
#include <stdio.h>
#include <stdlib.h>
#include "bevas.h"

int main()
{

int nehezseg=1;
char kerdes[100]="valami";
char A[20]="valami";
char B[20]="valami";
char C[20]="valami";
char D[20]="valami";
char valasz='C';
char kategoria[20]="valami";


Adatok *elso = ujelem(nehezseg, kerdes, A, B, C, D, valasz, kategoria);
Adatok *jelen;
FILE* fp=fopen("C:\\Users\\Zephyrus\\Desktop\\kerdes.csv","r");
if(fp==NULL ){
printf("HIBA:Nem tudtam megnyitni a fajlt");
}

while(fscanf(fp," %d;%s;%s;%s;%s;%s; %c;%s",&nehezseg,kerdes,A,B,C,D,&valasz,kategoria)!=EOF){
hozzafuz(elso,ujelem(nehezseg,kerdes,A,B,C,D,valasz,kategoria));
}
fclose(fp);

jelen=elso->kovetkezo;
while(jelen!= NULL){
printf("%d,%s,%s,%s,%s,%s,%c,%s\n",
jelen->nehezseg,
jelen->kerdes,
jelen->A,
jelen->B,
jelen->C,
jelen->D,
jelen->valasz,
jelen->kategoria);
jelen=jelen->kovetkezo;
}
felszabadit(elso);

return 0;
}
The first few lines of the source file:
1;Hol található a csarnokvíz?,a pályaudvaron;a szemben;a tejcsarnokban;barlangfürdőben;B;BIOLÓGIA
1;Melyik járműről elnevezett együttes tagja volt Zorán a 60-as években?;Villamos;HÉV;Autóbusz;Metró;D;ZENE

We have given you a number of suggestions to find out why your code is not working. The most important one that you seem to ignore, is to get the maximum error messages from the compiler. Your main.c element has the following:
C++
while(fscanf(fp," %d;%s;%s;%s;%s;%s; %c;%s",&nehezseg,kerdes,A,B,C,D,valasz,kategoria)!=EOF){
    hozzafuz(elso,ujelem(nehezseg,kerdes,A,B,C,D,valasz,kategoria));
}

and my compiler correctly noted that the parameter for a %c type, should be a pointer to a character variable, rather than the name. So change that to:
C++
while(fscanf(fp," %d;%s;%s;%s;%s;%s; %c;%s",&nehezseg,kerdes,A,B,C,D,&valasz,kategoria)!=EOF){
    hozzafuz(elso,ujelem(nehezseg,kerdes,A,B,C,D,valasz,kategoria));
}

And get rid of most of the lines in your .csv file; until your code works there is no point trying to process hundreds of lines, just use a few samples.

Other than that you need to do what we told you yesterday, and start using the debugger.
 
Share this answer
 
Comments
420bela 18-Nov-23 7:12am    
I rewrote my code, unfortunately it still doesn't work. Can you recommend a debugger?
Richard MacCutchan 18-Nov-23 7:17am    
I have not used Code::Blocks, so I do not know the answer, but I would again suggest you look at the documentation and see what they recommend.
Richard MacCutchan 18-Nov-23 7:56am    
See my new entry at Solution 3.
420bela 18-Nov-23 7:24am    
what documentation? Sorry but I am a complete beginner
Richard MacCutchan 18-Nov-23 7:30am    
Then I suggest you go to the Code::Blocks website and learn how to use their system. I also suggest you work through some tutorials on the C language. Get yourself a copy of the c programming language - Google Search[^.
 
Share this answer
 
Comments
420bela 18-Nov-23 7:14am    
The current code is not exactly the same as the previous ones
merano99 18-Nov-23 7:54am    
But the problems and my answers to them are the same. To be honest, I am shocked that the source code has regressed compared to the previous 3 versions. The source code is not even compilable. Instead of the discussed function for reading the (Hungarian) CSV file, fscanf is still used.
In addition, Kerdesek (Questions) was unnecessarily renamed to Adatok (Data). At least under Windows, reading the Hungarian CSV file with char strings does not work. Strings are unnecessarily copied several times without checking the length. In addition, there are many sprintf(), although you could simply copy strings with strncpy(). I had already noted that Hungarian special characters will probably not fit well in a char-string, but this is still being tried.
OK, I see what is wrong - the most annoying and useless C function ever invented: scanf!

Change the scan loop to the following:
C++
char buffer[256];
while (fgets(buffer, sizeof buffer, fp) != NULL)
{
    sscanf(buffer, "%d;%s;%s;%s;%s;%s;%c;%s", &nehezseg, kerdes, A, B, C, D, &valasz, kategoria);
    hozzafuz(elso,ujelem(nehezseg,kerdes,A,B,C,D,valasz,kategoria));
}
 
Share this answer
 
Comments
420bela 18-Nov-23 8:04am    
Thanks, now it's running. Unfortunately, it is still not good.The "nehezseg" is read well. But then the "kerdes" is not good, it only reads the first space. The rest is the "valami" at the beginning.
It says:
1,Hol,valami,valami,valami,valami,C,valami
1,Melyik,valami,valami,valami,valami,C,valami
1,Hogy,valami,valami,valami,valami,C,valami
1,Hol,valami,valami,valami,valami,C,valami
1,Hogyan,valami,valami,valami,valami,C,valami
Richard MacCutchan 18-Nov-23 8:13am    
Well I have done enough work on this problem, now it is your turn to learn how to debug your code.
420bela 18-Nov-23 9:12am    
Understandable. Thanks for your help. Can you recommend a good debugger? Or maybe you didn't interpret your answer correctly. I'm not perfect in English. Did you mean, should I try to figure out the error on my own or use a debugger
Richard MacCutchan 18-Nov-23 9:18am    
Your English is fine, my Hungarian does not exist.

Here is a link to the Code::Blocks page that mentions the debugger: Features - Code::Blocks[^]. I have not used that system so I do not know how easy it is. My recommendation would be to switch to Visual Studio 2022 Community Edition – Download Latest Free Version[^], which has a built in (very powerful) debugger. It is simple to use and shows you the content of any and all variables at each step in the code.
420bela 22-Nov-23 12:03pm    
Should I download visual studio or visual studio code? I'm sorry I'm writing now, but I haven't had the time, but now I'd like to finish my work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900