Thread: printing from output...

  1. #16
    Registered User
    Join Date
    Jul 2008
    Posts
    44
    wow, it worked.. Thank you very much! ^.^

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    int main(void)
    {
    	FILE *testFile;
    	int age;
    	char name[40];
    
    	system("cls");
    
    	testFile = fopen("c:\\testFile.txt", "w");
    
    	printf("\n\n\tEnter your name here: ");
    	gets(name);
    
    	printf("\tEnter your age here: ");
    	scanf("%i", &age);
    
    
    	fprintf(testFile, "The name you have inputed is: %s", name);
    	fprintf(testFile, "\nYour age is: %i", age);
    
    	fclose(testFile);
    
    	system("notepad.exe c:\\testFile.txt");
    
    	return 0;
    }
    ...uhmmm, about the fgets() thing, I don't get it what you mean... sorry...

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by ShadeS_07
    how?
    You could use something like:
    Code:
    char name[40];
    
    /* ... */
    
    if (fgets(name, 40, stdin))
    {
        char *newline_ptr = strchr(name, '\n');
        if (newline_ptr)
        {
            *newline_ptr = '\0';
        }
    }
    else
    {
        /* Read error or pre-mature EOF. */
    }
    Last edited by laserlight; 12-25-2008 at 01:22 AM. Reason: Simplification and bug fix.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printing output
    By TAboy24 in forum C Programming
    Replies: 2
    Last Post: 12-07-2007, 12:41 AM
  2. Output an array in a textbox
    By Diablo02 in forum C# Programming
    Replies: 5
    Last Post: 10-18-2007, 03:56 AM
  3. Printing to file / Output issues
    By Roflcopter in forum C++ Programming
    Replies: 19
    Last Post: 10-11-2007, 07:38 PM
  4. sorting output on student info program
    By indigo0086 in forum C++ Programming
    Replies: 2
    Last Post: 11-05-2002, 11:29 AM
  5. printing output from prog
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 08:50 PM