Hello,
I am experimenting with structure and trying to assign
address of a struct type and print a members value,
but I get many errors. Please see code below;
Code:
#include <iostream>
using namespace std;
struct Num {
unsigned int total;
};
void Set(struct Num *nn) {
nn->total = 99;
}
int main () {
struct Num spike;
struct Num *NewPtr;
NewPtr=&spike;
NewPtr->total = 5;
Set(NewPtr);
printf("\ns.total =
%d\n", NewPtr->total);
}
here are errors:
compiler.cpp:60:9: warning: missing terminating " character
60 | printf("\ns.total =
| ^
compiler.cpp:60:9: error: missing terminating " character
60 | printf("\ns.total =
| ^~~~~~~~~~~~
compiler.cpp:61:4: error: stray '\' in program
61 | %d\n", NewPtr->total);
| ^
compiler.cpp:61:6: warning: missing terminating " character
61 | %d\n", NewPtr->total);
| ^
compiler.cpp:61:6: error: missing terminating " character
61 | %d\n", NewPtr->total);
| ^~~~~~~~~~~~~~~~~~
compiler.cpp: In function 'int main()':
compiler.cpp:61:2: error: expected primary-expression before '%' token
61 | %d\n", NewPtr->total);
| ^
compiler.cpp:61:3: error: 'd' was not declared in this scope
61 | %d\n", NewPtr->total);
| ^
thank you