0
#include<stdio.h>
//prints a shape using users input
int main() {
    int i, j ;
    char a ;
    i = 0 , j= 0;`

    printf("enter your charecter :");
    scanf("%s", &a);
    for ( j = 0; j < 5; j++)  { 
        for ( i = 0; i < 5; i++) {
         printf("%s", a);
        }
        printf("\n");
    }  
    return 0;
}

program stops after input by user

Jean-Baptiste Yunès
  • 34,548
  • 4
  • 48
  • 69
hirrrr
  • 1
  • 1
  • 1
    What are you trying to get from user: string or char? This https://stackoverflow.com/questions/13542055/how-to-do-scanf-for-single-char-in-c may help. – Askold Ilvento Oct 23 '22 at 07:56
  • `%s` is for C-strings and you gave a `char`(address of). At least try to declare `char a[10]` (to contain a C-string of length 9 max.). If you need to read a char, then use `char a = getchar()`. I/O are tricky. – Jean-Baptiste Yunès Oct 23 '22 at 08:06
  • You should figure out how to enable compiler warnings. The `scanf` mistake that others have pointed out may not give a warning, but `printf("%s", a);` will. – Paul Hankin Oct 23 '22 at 08:13

1 Answers1

0

&a does not refer to a string. %s will write all characters entered and nul terminate so will overrun the the single character to which &a refers.

You have the same format specifier mismatch for the output. The format specifier for a single character is %c, however in this case you could use getchar() / putchar().

Clifford
  • 88,407
  • 13
  • 85
  • 165