Thread: another super easy question

  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
    290
    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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    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
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    what is between "" counts as one string, so no - you have only one format string
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  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, 04:59 PM
  2. This is hopefully an extremely easy question...
    By rachaelvictoria in forum C Programming
    Replies: 2
    Last Post: 11-07-2005, 01: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