I've been developing a programm similar to the stable marriage problem.
I've just started but there is something wrong with the code. The 3rd argument of function saveToFile doesn't work. Can somebody help me?
I can't put it in code tags for some reason!
I've just started but there is something wrong with the code. The 3rd argument of function saveToFile doesn't work. Can somebody help me?
Code:
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <string.h>
//using namespace std;
void saveToFile(char* fileName, int numberOfPersons, char *namesOfPersons)
{
FILE *myFile;
if((myFile=fopen(fileName,"w"))==NULL)
{
printf("Cannot write file... Using already stored lists.");
exit(-1);
}
else
{
for(int i=0;i<numberOfPersons;i++)
{
fprintf(myFile, "%s\n",&namesOfPersons[i]);
}
fclose(myFile);
}
}
void dataEntry(char* requestFor)
{
int numberOfPersons;
printf("How many %ss? ",requestFor);
scanf("%d",&numberOfPersons);
char *namesOfPersons[numberOfPersons]; //Array of character array(string);
//Ask for Person names
for(int i=0;i<numberOfPersons;i++)
{
printf("%s name %d: ",requestFor,i);
scanf("%s",&namesOfPersons[i]);
}
saveToFile(strcat(requestFor,"List.txt"), numberOfPersons, &namesOfPersons);
}
int main(int argc, char *argv[])
{
dataEntry("Teacher");
dataEntry("Student");
dataEntry("Diplwmatikes");
system("PAUSE");
return EXIT_SUCCESS;
}
Comment