Home > Blockchain >  i need help because of these constant nulls in C
i need help because of these constant nulls in C

Time:10-13

this is my code and I have been getting constant nulls from it so I do need a help

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

int main () {       
    char jojo[100];
    
    printf("name: ");
    scanf("[^\n]*c", &jojo);
    printf("Happy Birthday to %s.\n");
    
    printf("\n");       
    return 0;       
}

CodePudding user response:

For starters in the call of scanf

scanf("[^\n]*c", &jojo);

you shall not use a pointer to the character array. Also you need to use the symbol '%' before the conversion specifiers.

Instead write

scanf("%[^\n]%*c", jojo);

In the call of printf you forgot to specify the argument that represents the array.

printf("Happy Birthday to %s.\n");

write

printf("Happy Birthday to %s.\n", jojo);

Here is a demonstrative program.

#include <stdio.h>

int main(void) 
{
    char jojo[100];
    
    printf( "name: " );
    scanf("           
  • Related