Thread: Get text from input and save each word with malloc

  1. #1
    Registered User
    Join Date
    Dec 2014
    Posts
    3

    Unhappy Get text from input and save each word with malloc

    Hello I am new here and generally I am new in C.I want to write a program which takes a text from input and saves each word with malloc.For example for text "Have a nice a day" i want an array for each word, have,a,nice etc.Your help would be very useful.Thanks in advance.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,267
    You can use fgets() to gather the user input strings. Then use strcpy() to copy the user's words into your buffers you created with malloc. You can break the text into words by parsing the data on your own, or you can use a helper function like strtok(). Your buffers will now need to be saved somewhere. You could store them in an array, or you could create something more sophisticated like a linked list.
    bit∙hub [bit-huhb] n. A source and destination for information.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. find word and insert another word after that in text
    By xiromdim in forum C Programming
    Replies: 8
    Last Post: 12-20-2013, 11:54 AM
  2. Replies: 6
    Last Post: 09-23-2013, 02:59 AM
  3. Replies: 2
    Last Post: 09-22-2013, 12:53 PM
  4. reading text-and-numbers file word by word
    By bored_guy in forum C Programming
    Replies: 22
    Last Post: 10-26-2009, 10:59 PM
  5. Help reading text file word by word
    By Unregistered in forum C++ Programming
    Replies: 6
    Last Post: 05-25-2002, 05:13 PM

Tags for this Thread