Question Regarding Compiling C on OnlineGDB
Are there any online compilers that allow projects and can surpass OnlineGDB's 100kb limit?
Why is onlineGDB not giving the same result as another compiler?
Videos
I'm so, so sorry if this post is not appropriate here, but I am a very new programmer and I'm really struggling to find an answer here. If this is the wrong place for this post, please let me know and I will delete it ASAP.
I'm currently enrolled in an intro programming class learning C. We use OnlineGDB as our compiler, and we are currently working on a project that is teaching us to read data from a file and store that data in various arrays.
I'm understanding all the concepts and my code executes perfectly - UNTIL I declare a new variable. Any kind of variable, in any part of the main function. If I declare any new variable, my code stops working at all. There are no errors - but there is also no output.
I've talked with multiple TAs from my class, and they either can't figure out what's going on, or they won't tell me. I've googled everything I can think to Google, and can't find any answers. I'm desperate at this point.
Again, if this post is inappropriate, I apologize and will remove it immediately. But if not, I would so greatly appreciate any help you guys can give me.
Thanks in advance.
Edit: Here is my code. All of the array declarations that are commented out cause the issue described above. If I try to add even one of them, I get no output.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const int SUPNUM = 30;
const int NAMLEN = 29;
int findSmYear(int pubYear[], int recYear, int count);
int main()
{
char lastNm[SUPNUM][NAMLEN];
char firstNm[SUPNUM][NAMLEN];
char superNm[SUPNUM][NAMLEN];
//char pubNm[SUPNUM][NAMLEN];
//char pantheonNm[SUPNUM][NAMLEN];
//char eyeColor[SUPNUM][NAMLEN];
//char species[SUPNUM][NAMLEN];
//char hairColor[SUPNUM][NAMLEN];
char gender[30];
int pubYear[30];
//int issueNum[30];
//int movieYear[30];
//double height[30];
//double weight[30];
int count;
char *word[NAMLEN];
char fline[128];
FILE * shIn;
char fileNm[] = "n.txt";
shIn = fopen(fileNm, "r");
if (shIn == NULL)
printf("ERROR: File not found.");
else
{
count = 0;
while (!feof(shIn))
{
fgets(fline, 128, shIn);
strcpy(lastNm[count], strtok(fline, ","));
strcpy(firstNm[count], strtok(NULL, ";"));
gender[count] = *strtok(NULL, " ");
strcpy(*word, strtok(NULL, " "));
strcpy(superNm[count], "");
while (atof(*word) == 0)
{
strcat(superNm[count], *word);
strcat(superNm[count], " ");
strcpy(*word, strtok(NULL, " "));
}
pubYear[count] = atoi(*word);
count++;
} // End of while loop
for (int k = 0; k < count; k++)
{
printf("%d. %s %s, AKA %s - %c - First published in %d\n",
k + 1, firstNm[k], lastNm[k], superNm[k], gender[k], pubYear[k]);
}
// Find the most recent publication year
int recYear = 0;
for (int k = 0; k < count; k++)
{
if (pubYear[k] > recYear)
recYear = pubYear[k];
}
printf("\nThe most recent publication year is %d.\n\n", recYear);
// Find the earliest publication year using a function
int earlYear = findSmYear(pubYear, recYear, count);
printf("The earliest publication year is %d.\n\n", earlYear);
// Find the first alphabetical superhero name
int alpha = 0;
for (int k = 0; k < count; k++)
if (strcmp(superNm[k], superNm[alpha]) < 0)
alpha = k;
printf("The first superhero name alphabetically is %s.\n\n", superNm[alpha]);
} // End of else loop
return 0;
}
int findSmYear(int seeYear[], int bigYear, int count)
{
int smYear = bigYear;
for(int k = 0; k < count; k++)
{
if(seeYear[k] < smYear)
smYear = seeYear[k];
}
return smYear;
}Perhaps I should add that this issue occurred once before when trying to initialize the int earlYear variable (only when initializing it, not declaring it). A TA fixed it by changing the name of the file that the program is reading from (name changed from shDataSpr22A.txt to n.txt), but declined to explain why this fixed the issue.
For whatever reason, I really can't use Visual Studios Code. It says g++ not recognized even after I installed MSYS2 and added it as a path in my environment variables.
I just want to finish an assignment so I can relax for the rest of the week
The code is extremely sloppy, I'm just trying to get my program to work. After half an hour of trying to figure out why 2 strings that were exactly the same in the expression string1==string2 had it evaluating to 0, I tried another compiler. It worked there. Why is GDB doing this?