another super easy question

This is a discussion on another super easy question within the C Programming forums, part of the General Programming Boards category; My question is y am i getting a garbage ouput when i compile this Code: #include<stdio.h> #include<conio.h> #include<stdlib.h> int main ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    62

    another super easy question

    My question is y am i getting a garbage ouput when i compile this
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    
    int main ( )
    {     
        system("cls");
        printf("%-20s Description, %-10s Smarties\n\n");
         getch();
    }

  2. #2
    Registered User
    Join Date
    Jan 2008
    Posts
    287
    Because you meant to write:
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    
    int main ( )
    {     
        system("cls");
        printf("%-20s %-10s\n\n", "Description",  "Smarties");
        getch();
    }
    There's no sense in telling printf that you're going to pass it 2 strings if you don't pass it 2 strings.

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    because you are lucky. I would think the correct output for this progrma will be a crash...

    don't even try to mismath format of scanf/printf and parameters you pass
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    62
    i think i have two strings which is description and smarties thought am i wrong??

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    what is between "" counts as one string, so no - you have only one format string
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Which means, at the end, that you have no strings at all as parameters -- your format string is there, but your format string needs two parameter strings, one for each %s, and both of those are just plain not there.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another Embarassingly Easy Question
    By almo89 in forum C Programming
    Replies: 2
    Last Post: 02-11-2006, 03:59 PM
  2. This is hopefully an extremely easy question...
    By rachaelvictoria in forum C Programming
    Replies: 2
    Last Post: 11-07-2005, 12:36 AM
  3. 4 easy question
    By Zeratulsdomain in forum C++ Programming
    Replies: 2
    Last Post: 10-15-2005, 10:43 PM
  4. easy question about machine code
    By Jaguar in forum Tech Board
    Replies: 3
    Last Post: 10-07-2003, 09:11 AM
  5. Easy Question
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 08-12-2002, 12:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21