Thread: Need help with this program! (Beginner)

  1. #1
    Registered User
    Join Date
    Jun 2018
    Posts
    3

    Need help with this program! (Beginner)

    Code:
    #include <stdio.h>
    #include<stdlib.h>
    #pragma warning (disable:4996)
    
    
    void main()
    {
    	char name[20];
    	char addr1[15];
    	char addr2[15];
    	char addr3[15];
    
    
    	printf("Enter customer name > ");
    	scanf("%[^/n]", name);
    	printf("Enter Address in 3 lines:\n");
    	printf("   Line 1  > ");
    	rewind(stdin);
    	scanf("%[^/n]", addr1);
    	printf("   Line 2  > ");
    	rewind(stdin);
    	scanf("%[^/n]", addr2);
    	printf("   Line 3  > ");
    	rewind(stdin);
    	scanf("%[^/n]", addr3);
    
    
    	printf("\n%s, your ordered itens will be sent to:\n", name);
    	printf("%s", addr1);
    	printf("\n%s", addr2);
    	printf("\n%s", addr3);
    
    
    	system("pause");
    }
    It wont output another line when i input the name

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,415
    1. main returns int, not void.
    2. What are all those rewind(stdin) calls supposed to be doing?
    3. Your scanf sets should have \n not /n if you want everything up to a newline.
    4. You need to get rid of that newline somehow.
    5. Use fgets() if you want a safe way to read a whole line.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Oct 2017
    Posts
    36
    Also, do not forget to place comments in your code.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    3,653
    Quote Originally Posted by splitfunc0 View Post
    Also, do not forget to place comments in your code.
    Wrong! Place meaningful comments in your code! The worst code maintenance mistake I see, is newbies make is placing useless and meaningless comments in their code.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Oct 2017
    Posts
    36
    Quote Originally Posted by stahta01 View Post
    Wrong! Place meaningful comments in your code! The worst code maintenance mistake I see, is newbies make is placing useless and meaningless comments in their code.

    Tim S.
    Noted. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help with Beginner Program
    By anchorblue804 in forum C++ Programming
    Replies: 2
    Last Post: 09-01-2012, 10:18 AM
  2. C Program beginner
    By striderx240 in forum C Programming
    Replies: 15
    Last Post: 01-26-2012, 10:17 PM
  3. Help beginner with program please
    By bubbles56 in forum C Programming
    Replies: 1
    Last Post: 03-23-2011, 10:37 PM
  4. Beginner, cant get my program to run :-(
    By leahknowles in forum C Programming
    Replies: 5
    Last Post: 03-23-2011, 03:44 PM
  5. Beginner C++ Help. My very first program.
    By Jechob in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2010, 01:34 PM

Tags for this Thread