Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7854745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:10:25+00:00 2026-06-02T20:10:25+00:00

I have a question simple like that: Let user enter some words from keyboard,one

  • 0

I have a question simple like that: Let user enter some words from keyboard,one word per line until a ‘.’ (period) entered then print out result, for example:

Enter a word: word1
Enter a word: word2
Enter a word: .
You have entered 2 word(s):
word1
word2

OK here my try but when I run it said file has stopped working after let me enter first word

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>

int main () 
{ 
    char *word[50]; //each word has maximum 49 character
    int i=0, number_of_word;

    do
    {
        printf ("Enter a word: ");
        scanf("%s", &word[i]);
        i++;
    }
    while (word[i][0]!='.');

    number_of_word =i;
    printf ("You entered %d word(s):\n", number_of_word);
    for (i=0; i<number_of_word; i++)
    {
        printf("%s\n", &word[i]);
    }

    return 0;
}

———————————————————————–

EDIT 1:

OK I try this, it worked but I am still looking for best way to declare an unknown size array of character string since I don’t know neither how many word user may enter nor how many letter of each word, in C++ it may called dynamic allocation array, I have no idea how to do it in C

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>

int main () 
{ 
    char word[20][50]; //array has maximum 20 words, each word maximum 50 character
    int i=0, number_of_word;

    do
    {

        printf ("Enter a word: ");
        scanf("%s", word[i]);
        i++;
    }
    while (word[i-1][0]!='.');

    number_of_word =i-1;
    printf ("You entered %d word(s):\n", number_of_word);
    for (i=0; i<number_of_word; i++)
    {
       printf("Word %d is %s\n", i, word[i]);
    }


    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:10:26+00:00Added an answer on June 2, 2026 at 8:10 pm

    You are not assigning any memory to store the individual strings, so your program invokes undefined behaviour.

    This:

    char *word[50];
    

    defines an array of 50 pointers, but no further storage.

    And when you do this:

    scanf("%s", &word[i]);
    

    you’re writing into the pointer array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple question. Let's say that I have this in robots.txt: User-agent:
Alright simple question I have integriters like 5 188 4634 And they all need
This is hopefully a simple question: I have an OpenGL texture and would like
This seems like such a simple question. I have several Edit boxes on my
may be too simple groovy question but....please help i have a list like this:
A really simple shell script question. I have a file with something like this:
I have simple question. User supplies URL to my PHP script where I fetch
I have a simple question, but I'm about 80% sure that the answer to
I have a simple question that I am posing mostly for my curiousity. What
I have a question that bothers me on some projects I'm currently working on.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.