Thread: input string of unknown length in c

  1. #1
    Registered User
    Join Date
    Apr 2018
    Posts
    43

    input string of unknown length in c

    is it even possible to write a program in c that prints out string input if unknown length to output only using getchar() and putchar()?

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,652
    Do you mean like this?
    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    int main() {
        int ch;
        while ((ch = getchar()) != EOF) {
            if (islower(ch))
                ch = toupper(ch);
            putchar(ch);
        }
        return 0;
    }
    And that's the world in a nutshell, an appropriate receptacle.

  3. #3
    Registered User
    Join Date
    Apr 2018
    Posts
    43
    hi thx for your answer

    in my assignment it says that I can only use the std library <stdio.h>

    I have been trying for over an hour and I can't get it. I have no Idea how it should work .

  4. #4
    Registered User
    Join Date
    Dec 2017
    Posts
    1,652
    I didn't realize something so basic could be an "assignment". But the answer's there. It just has more than you need.
    And that's the world in a nutshell, an appropriate receptacle.

  5. #5
    Registered User
    Join Date
    Apr 2018
    Posts
    43
    sry just ignore my first reply

    and no thats the beginning of the assignment

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading in file of unknown length
    By zone159 in forum C Programming
    Replies: 2
    Last Post: 11-14-2012, 02:07 PM
  2. Reading from a textfile with unknown length?
    By chickenlittle in forum C++ Programming
    Replies: 4
    Last Post: 09-10-2011, 11:59 PM
  3. Replies: 20
    Last Post: 03-08-2011, 05:16 PM
  4. reading a file of unknown length
    By the bassinvader in forum C Programming
    Replies: 2
    Last Post: 07-12-2006, 03:06 PM
  5. Replies: 1
    Last Post: 07-10-2006, 06:30 AM

Tags for this Thread