Thread: How to scan many string and print later

  1. #1
    Registered User
    Join Date
    Jul 2018
    Posts
    81

    How to scan many string and print later

    I want to scan the days and later want to display without any header file

    Get the data from user

    Tuesday
    Wednesday
    Monday
    Thursday
    Friday

    Display the day entered by user

    Tuesday
    Wednesday
    Monday
    Thursday
    Friday

    I tried
    Code:
    #include<stdio.h> 
    int main()
    {
       int i;
        
       char days[8];
       for ( i = 0; i < 7; i++)
       {
            scanf("%s",days);
       }
       
       for ( i = 0; i < 7; i++)
       {
           printf ("Day %s \n", days[i]);
       }
        
       return 0;
    
    }
    i have to store 7 strings

    How can we do this without any header file
    Last edited by vajra11; 11-15-2019 at 07:37 AM.

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    The C language consists of aproximatly 44 keywords, and approximately 47 operators, and many rules concerning them.

    All the rest are contained within the Standard Library, a set of pre-compiled functions available in all C Standards complaint compilers.

    With that in mind, it would be almost impossible to perform any input and output without the use of the functions, #defines and other data contained in those header files, and the Standard Library functions linked in by the linker. You would have to write them yourself, and I don't recommend even attempting this!!!

    If this is an assignment by a instructor, then your answer should be that no, it is not possible. I smell a trick question here! ;^)

  3. #3
    Registered User
    Join Date
    Jul 2018
    Posts
    81
    Quote Originally Posted by rstanley View Post

    If this is an assignment by a instructor, then your answer should be that no, it is not possible. I smell a trick question here! ;^)
    No I was just experimenting

  4. #4
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,111
    Actually you could input them using command line arguments, but outputting them would be the trick! ;^)
    Code:
    $ ./prog Tuesday Wednesday ...
    Also, in your code, you are overwriting each word with the next one, and then attempting to print out the last word input 7 times. You would need an two dimensional array, such as
    Code:
    char days[7][12]
    "Wednesday" is 9 characters, and you would need at least 10 chars for the word, plus the terminating Nul byte.

    Your code should not compile without errors or warnings. days[i] is a char and the format specifier , %s expects a string.

    Please turn on and turn up your compiler warning level to the highest!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 09-07-2019, 05:11 PM
  2. Replies: 3
    Last Post: 06-16-2013, 01:28 AM
  3. How do i scan and print an integer?
    By ziggy786 in forum C Programming
    Replies: 3
    Last Post: 01-28-2013, 06:05 PM
  4. scan an image and print it
    By hephaest in forum C Programming
    Replies: 18
    Last Post: 09-08-2006, 04:34 PM
  5. scan a string
    By Max in forum C Programming
    Replies: 4
    Last Post: 12-02-2002, 04:26 PM

Tags for this Thread