1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Simpel question in C (tcshell) about strings and pointers

  1. Jan 12, 2012 #1
    If I need to write a c program which get a string from the stdin and prints it after a certain manipulation, the program is called that way:
    Code (Text):
    echo "Hello, World. bla bla bla" | program <arg>
    How can I save the string in my program before working on it?

    Thanks in advance
     
  2. jcsd
  3. Jan 12, 2012 #2

    LCKurtz

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    Try
    Code (Text):

    char instring[40];
    fscanf(stdin,"%s",instring):
    where use 40 or whatever your max string length is. Your string is located at the address pointed to by the pointer instring.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Simpel question in C (tcshell) about strings and pointers
  1. C pointer question (Replies: 1)

Loading...