When i try to compile my code i get the following errors:
error #2168: Operands of '=' have incompatible types 'char [255]' and 'char *'.
error #2088: Lvalue required.
i get these errors for the same line (ie 1044), and on a multiple of lines, so i figure by fixing one i can fix the others, so let me copy you the codes. You can skip and only read lines where comments start with ** just to make it easier :) and ending with <-- I hope the in code comments serve you well: first let me start by defining the type PRINTOPT
typedef struct {
//UsePl signifies if the user would like to see the graphs without having to export data
//Thanks to PlPlot library.
int usePl;
//Feel free to customize and add to this struct
//for any simulation program you create.
//---- Note2self: probably change the graph bool to an array,
//as later you will have to print around 20 graphs or so
int thetaGraph; //Plot Theta VS Time
int omegaGraph; //Plot Omega VS Time
char filename[255]; //**I have declared it to be a 255 char. <============
int matlab; //0 no, not 0 yes;
} PRINTOPT;
function which raises the error int ReadPrintOpt(PRINTOPT *opt) { int input;
int usePl;
int thetaGraph;
int omegaGraph;
//**The result behind this def, i would like the user to input a filename
//To save his data in, <========================================================
char filename[255] = "Osc Motion and Chaos- Results"; //I have declared filename as char [255]
int matlab;
printf("\n----Print Options----\n");
printf("\nMENU (choose one of the following commands)\n");
printf("\n\t 1 - Display Graphs after Simulation\t\t\tCurrent Val\t\"%d\"",opt->usePl);
printf("\n\t 2 - Enable Theta vs Time Graph\t\tCurrent Val\t\"%d\"",opt->thetaGraph);
printf("\n\t 3 - Enable Omega vs Time Graph\t\tCurrent Val\t\"%d\"",opt->omegaGraph);
printf("\n\t 4 - Save Data in Matlab Format\t\tCurrent Val\t%d",opt->matlab);
printf("\n\t 5 - Filename for exported files\t\tCurrent Val\t%s",opt->filename);
printf("\n\n\t 0 - <DONE>\n>>");
scanf("%d",&input);
switch(input) {
case 0:
return 0;
case 5:
printf("Enter Filename: ");
fgets(filename, 255, stdin); //**i've been told to use this, saw it on another question
opt->filename = filename; //**In this part, opt is of type PRINTOPT
//I have been told that the name of an array, is actually
//a pointer to the first element, so why does this part
//give me this error -- Operands of '=' have incompatible types 'char[255] and [char*]
//although i've declared both as char[255];
break;
case 4:
printf("Enable Matlab (0 no, else yes): ");
scanf("%d",&matlab);
opt->matlab = matlab;
break;
case 1:
printf("Use this program to display plots (0 no, else yes): ");
scanf("%d",&usePl);
opt->usePl = usePl;
break;
case 2:
printf("Record Data for Graph of Theta (0 no, else yes): ");
scanf("%d",&thetaGraph);
opt->thetaGraph = thetaGraph;
break;
case 3:
printf("Record Data for Graph of Omega (0 no, else yes): ");
scanf("%d",&omegaGraph);
opt->omegaGraph = omegaGraph;
break;
default:
printf("Invalid Input!");
break;
}
return 1;
}
anyways, i believe i have declared both filename as 255 char, .. the compiler doesnt make mistakes.. so i figured it is me :) where did i go wrong? The idea is i have a function that creates a sweep over a parameters, such as the driving force.. and i need the simulation to dump files of that data: - results1.txt - results2.txt - results3.txt
which raises another question, but i surely find the answer to it, google... how can i transform from int to char in c. Simple casting probably?
thanks again