0
#include <stdio.h>
int main() {
  int n, i;
  char arr[20];
  clrscr();
  printf("Enter size of array(<=20)");
  scanf("%d", &n);
  printf("Enter array");
  for (i = 0; i < n; i++) {
    scanf("%s", &arr[i]);
  }
  for (i = 0; i < n; i++) {
    printf("%s", arr[i]);
  }

  getch();
  return 0;
}

The program does not prints the array and instead shows Program termination message

The image shows the program termiantion message

5
  • 1
    @ajas Paunikar The conversion specifier %s is used with character arrays that contain strings. You are using this specifier with scalar objects of the type char. Commented Apr 16, 2020 at 11:03
  • 1
    char arr[20]; does not mean an array of 20 strings, with each string being big enough to hold the entire text of "Harry Potter And The Sorcerer's Stone". You cannot expect to be able to enter the entire text of each Harry Potter book in response to "Enter Array", and have it fit inside your char arr[20];. C does not work this way. Commented Apr 16, 2020 at 11:03
  • What should I do? Commented Apr 16, 2020 at 11:09
  • 1
    @RajasPaunikar We cannot tell you what to do if we don't know what exactly your program is supposed to do. You want an array of number or an array of strings or an array of characters or ...? Commented Apr 16, 2020 at 11:23
  • I wanted the program to read the array and then print it. I changed the %s to %c from printf("%s" , arr[i]); Now it works Thank you everyone Commented Apr 16, 2020 at 11:55

1 Answer 1

1

The problem is with the line

printf("%s", arr[i]);.

If you change this line to

printf("%c", arr[i]);

then it will work because %s is used with character arrays that contain strings

I am just giving the solution for your program termination. Still we can do some modification in your code.

Thanks

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.