2 Replies - 2117 Views - Last Post: 27 October 2007 - 08:33 AM Rate Topic: -----

#1 Jingle  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 317
  • Joined: 20-October 07

fputs

Post icon  Posted 26 October 2007 - 09:50 PM

im having trouble printing a variables value. with fputs i can make a file
and write to it i just cant print a char variable or watever it is to it.
any help would be much apreciated
and i now my code is pretty ruf so if there are any other sugestions they would
be much apreciated.
// Go Xcode!!!!!! MeJ.J. 
#include <stdio.h>
#include <iostream>		
#include <stdlib.h>

using namespace std;
					// declaring all global variables
	char ch[255]; 
	char fc[255];
	char ff[255];

	char te = 0;
	char name[255];
	
					// declaring all functions
void run(void);
void greetN();
void test(void);
void get_str(char *, int);
void Name();
int main(void)
{
	run();
	return 0;
}

void run(void)		//runs everything
{
	test();			//tests name for recognition
	greetN();		//for new names
}

void get_str(char *buf, int buf_size) 
{
	int i=0;
	while((i<buf_size-1) && (buf[i]=getchar()) && (buf[i] != '\n')) i++;
	buf[i] = '\0';
}

void greetN()
{
	cout<< "what is your Name?\n";			//
	get_str(name,255);
	cout<< "what is your favorit food?\n";
	get_str(ff,255);
	cout<< "what is your favorit color\n";
	get_str(fc,255);
	printf(" hello ");
	cout<< name<<" don't worry I won't forget I have a photographic memory!"
	 <<endl<<"so if you ever need me again."
	 <<endl<<" tell me your name and you'l have all the imformation on what I have asked you and your answeres."
	 <<endl<<" I never forget anything I have a photographic memory.";
	Name();
}
void test(void)
{
	char buf[3];
	printf("Are you new?  y/n\n");
	get_str(buf,3);
	switch(buf[0]) {
		case 'Y' :
		case 'y' : 
			printf("type your name for Recognition\n");
			break;
		case'n':
		case'N': 
			greetN(); 
			break;
		default:
			printf("\ny/n");
			break;
	}
}
void Name()
{
  FILE * pFile;
  pFile = fopen (name,"w");
  if (pFile!=NULL)
  {
	fputs ("favorit color\t%",ff,pFile);
	//fputs ("favorit food\t",pFile,ff);
	fclose (pFile);
  }
}



Is This A Good Question/Topic? 0
  • +

Replies To: fputs

#2 no2pencil  Icon User is online

  • Head MFIC
  • member icon

Reputation: 5066
  • View blog
  • Posts: 26,449
  • Joined: 10-May 07

Re: fputs

Posted 27 October 2007 - 12:40 AM

Why not use fprintf? That way you can have complete control over it's output like you would with printf.
Was This Post Helpful? 0
  • +
  • -

#3 Jingle  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 317
  • Joined: 20-October 07

Re: fputs

Posted 27 October 2007 - 08:33 AM

View Postno2pencil, on 27 Oct, 2007 - 12:40 AM, said:

Why not use fprintf? That way you can have complete control over it's output like you would with printf.

il give it a shot
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1