how to make string variable in c code example
Example 1: string in c
#include <stdio.h>
int main(void) {
char name[] = "Harry Potter";
printf("%c", *name);
printf("%c", *(name+1));
printf("%c", *(name+7));
char *namePtr;
namePtr = name;
printf("%c", *namePtr);
printf("%c", *(namePtr+1));
printf("%c", *(namePtr+7));
}
Example 2: how to create a string in c
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
char greeting[] = "Hello";
Example 3: string in c
#include <stdio.h>
void displayString(char str[]);
int main()
{
char str[50];
printf("Enter string: ");
fgets(str, sizeof(str), stdin);
displayString(str);
return 0;
}
void displayString(char str[])
{
printf("String Output: ");
puts(str);
}