I have no idea what I'm doing the most of the time, I try and explain it.
I am suppose to make a social program that is basically twitter but in a console application for C++. It is suppose to write/save a user's message if they choose choice 1 and read from a file provided if they choose choice 3. There are several errors in this code and I have no idea how to fix it. I am mostly new to C++ in general. Can you please help me? (Ignore choice 2, I eventually fix that myself)
#include <stdio.h>
#include <string.h>
void printMessage(struct message_data M)
{
int msgLeng = strlen(M.message);
printf("ID - %s : MsgLength - %d : Upvotes - %d\n%s\n", M.userid, msgLeng, M.upvotes, M.message);
}
struct message_data
{
char userid[11];
char message[142];
int upvotes;
}
mainpage(void)
{
struct message_data message1;
FILE *CAWCAW; // File Pointer
int menuchoice;
// Show menu choices
printf("Welcome to CawCaw! Please don't sue us!\n");
printf("Welcome to the main menu of Twitt- I meant CawCaw!\n");
printf("Type in 1 for new CAWS\n");
printf("Type in 2 for viewing CAWSCAWS\n");
printf("Type in 3 for loading a CAWCAW from a file\n");
//printf("Type in 4 to quit CAWCAW\n"); (NOT NEED FOR NOW, JT 30/11/15)
//Menu choice
scanf("%d", &menuchoice);
//Case statements
switch (menuchoice)
{
case 1: //Adding a new caw
{
printf("WHAT'S YOUR CAW NAME? \n");
fscanf(CAWCAW, " %[^\n]", &message1.userid);
printf("WHAT'S YOUR CAW STRANGER? \n");
fscanf(CAWCAW, " %[^\n]", &message1.message);
printf("THANK YOU STRANGER, YOUR CAW HAS BEEN UPLOADED \n");
//^^^ Asks users for details , such as name messages, whatever
}
break;
case 2: // Viewing cawcaws
{
}
break;
case 3: //Loading a cawcaw from a file
{
CAWCAW = fopen("D:/FILEDIRECTORY/FOLDER", "r"); //PLEASE CHANGE DIRECTORY TO THE CORRECT ONE WHEN LOADED FOR REAL!
char userid[11];
char message[142];
int upvotes;
while (!feof(CAWCAW))
{
fscanf(CAWCAW, "%10[^|]|%141[^|]|%d", &userid, &message, &upvotes);
printf("%s, %d, %d\n", userid, message, upvotes);
}
fclose(CAWCAW);
}
break;
default:
{
printf("PLEASE PUT IN A VALID CHOICE NUMBER, CAW CAW! \n");
}
}
}
The new errors I am getting are this:
Severity Code Description Project File Line
Error C2027 use of undefined type 'message_data' NOTTWITTERCAWCAW 6
Error C2228 left of '.message' must have class/struct/union NOTTWITTERCAWCAW 6
Error C2027 use of undefined type 'message_data' NOTTWITTERCAWCAW 7
Error C2228 left of '.userid' must have class/struct/union NOTTWITTERCAWCAW 7
Error C2228 left of '.upvotes' must have class/struct/union NOTTWITTERCAWCAW 7
Error C2228 left of '.message' must have class/struct/union NOTTWITTERCAWCAW 7