[Solved] How to pass structure by reference in C?

Here is the problem, void readStructs(tMystruct *theVar) { scanf(“%d”,theVar.id); //<——problem scanf(“%f”,theVar.length); //<——problem } You should access Structure pointer member using -> operator and also you’re missing & that will eventually cause a segmentation fault. Here is the modified code, void readStructs(tMystruct *theVar) { scanf(“%d”,&theVar->id); scanf(“%f”,&theVar->length); } solved How to pass structure by reference in C?

[Solved] Printing Array in struct

You can’t print the two values by using x[i]. You must print them one-by-one. You probably want something like: for (i=0;i<12;i++) { printf(“\t index %d value %f, %f \n\r”,i, x[i].a, x[i].b); } 1 solved Printing Array in struct

[Solved] How to read data from a text file into a struct

Random act of madness kindness: Live On Coliru #include <fstream> #include <set> struct Person { std::string name; std::string nationality; std::set<std::string> hobbies; friend std::istream& operator>>(std::istream& is, Person& into) { size_t n = 0; if (getline(is, into.name) && getline(is, into.nationality) && is >> n && is.ignore(1024, ‘\n’)) { while (n–) { std::string hobby; if (getline(is, hobby)) into.hobbies.insert(hobby); … Read more

[Solved] C++field of struct if error

restavracija is a type, not an object. You have to instantiate it to produce an object. In this particular case, it looks like you’re expecting an array of them, and you want to call that array polje. Such an array declaration will look something like: restavracija polje[10]; Accessing element i in that array will then … Read more

[Solved] Why does incrementing a pointer work, but treating it as an array fail? Part 2 [closed]

I’m not sure what your question is, but this code probably doesn’t do what you want: printf(“main Pointer to struct.” EOL); for (int i=0; i<count; i++) { printf(“index: %d useless1: %d” EOL, i, b->useless1); printf(“index: %d useless2: %d” EOL, i, b->useless2); b++; } printf(EOL); printf(“main Index into array of structures.” EOL); for (int i=0; i<count; … Read more

[Solved] Push pop stack operation in C [closed]

Here you have again some things wrong. Before you create new threads with similar content, stick to one thread. In your code you also never check if malloc fails. It’s always better to do that. For simplicity I’ve omitted these checks in my suggestions. 1. Why do you do S1[0].top=-1; in makeEmpty? create already does … Read more

[Solved] my output of link list is not correct? [closed]

Remember pressing Enter after entering data for the previous scanf? This newline character is consumed by the scanf with a %c. You have to change scanf(“%c”,&ch); fflush(stdin); to scanf(” %c”, &ch); so that the scanf will skip the newline character left over by the previous scanf. The space before %c is a whitespace character and … Read more

[Solved] How do I compare chars (or strings) using void functions, also comparing chars that were taken from a struct array

If I understand you correctly, you have a structure containing several members of different types and you are looking for a way how you could compare instances of this struct. It could look the following way: struct X { std::string s; char c; int i; bool operator==(const X& ref) { return s == ref.s && … Read more

[Solved] c++ – How to use a function in a Struct?

You must declare func2 before newNode. Forward references are not possible. possibly, you DID declare func2 before but it had a compile error itself, please check further above in the log. By the way, newNode is not “the struct”. “The struct” is that variable what you have named node and is not declared, which does … Read more