4 Replies - 406 Views - Last Post: 07 October 2012 - 02:39 AM Rate Topic: -----

#1 cjayaranon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-October 12

a project that simulates an Online Journal

Posted 06 October 2012 - 10:04 PM

good day programmers.. i have been on this project lately. i am trying to make a simulation of an Online Journal.
in the first part is the Main Menu. after it is the sub-menu if you choose 'A'..
on that sub-menu i have trouble accessing my structured data type struct clients. what do i have to do?

#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>



struct clients{
	   char fName[15];
	   char uName[10];
	   char pWord[10];
	   int dJoined[10];
	   int dEntry[10];
	   int tEntry[8];
	   char journal[];
	   };
	   
int main(){
	
	printf("MAIN MENU\n[A] New User\n[B] Old User\n[C] Quit\n\n");
	ch = getche();
	ch = toupper(ch);
	
	   while(ch=='A'||'B'||'C'){
				if(ch=='A'){
							
	FILE *cfPtr;
	
		 if((cfPtr=fopen("users.txt","w"))==NULL){
		 											printf("File could not be opened\n");
													}
													
			else{
				 printf("\nEnter the Full Name\nUser Name\nPassword\nDate Joined.\nEnter EOF to end input.\n");
				 printf("-");
				 scanf("%s%s%s%d", clients.fName, clients.uName, clients.pWord, clients.dJoined);
				 
				 while(!feof(stdin)){
				 					 fprintf(cfPtr, "%s* %s* %s* %d*\n", fName, uName, pWord, dJoined);
				 					 printf("-");
				 					 scanf("%s%s%s%d", &fName, &uName, &pWord, dJoined);
									 }
									 
									 fclose(cfPtr);
									 }
									 }
									 }
									 }


i also got this error messages..
 G:\proj.cpp expected primary-expression before '.' token


Is This A Good Question/Topic? 0
  • +

Replies To: a project that simulates an Online Journal

#2 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 769
  • View blog
  • Posts: 2,245
  • Joined: 20-March 10

Re: a project that simulates an Online Journal

Posted 06 October 2012 - 10:16 PM

Hi,

You have a struct called clients so in main you have to instantiate a new instance of the struct

like this

clients newclient;

then you can access it by

newclient.fName etc..


You have other errors...

Snoopy.
Was This Post Helpful? 1
  • +
  • -

#3 jdavi134  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 225
  • Joined: 26-October 11

Re: a project that simulates an Online Journal

Posted 06 October 2012 - 10:26 PM

Snoopy said that perfectly.

But for future reference. Formatting your code to be easily read by anyone trying to read it can come in handy. I hate to say it but this code looks like a jumbled mess and is one of my biggest pet peeves.

Just a quick tip. Line up corresponding: curly braces, statements/expressions that might take up more than one line, method headers, etc.. If you want a quick simple example, try this link below. It will give you a short 10-12 line code piece that is well formatted and universally easy to read.

Formatting

Happy Coding =)
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3552
  • View blog
  • Posts: 11,008
  • Joined: 05-May 12

Re: a project that simulates an Online Journal

Posted 06 October 2012 - 10:44 PM

As an aside, you seem to be saving your code into .cpp file indicating that you want write C++ code, yet the code you have posted seems to be primarily C code with the use of printf(), fopen(), etc.
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: a project that simulates an Online Journal

Posted 07 October 2012 - 02:39 AM

while(ch=='A'||'B'||'C')


Nope, doesn't work the way you think.

char journal[];


Again, wrong. you have to give an array a size at the time of declaration.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1