xxxxxxxxxx
int main()
{
char str[]={'g','l','o','b','e','\0'};
printf("%s",str);
return 0;
}
xxxxxxxxxx
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define MAX_LENGTH 100
#define NUM_STRINGS 10
int main(){
char arr[NUM_STRINGS][MAX_LENGTH] = {""};
arr2[0] = "string literal"; // Not permitted
strcpy(arr[0], "hello world");
printf("%s\n", arr[0]);
printf("%s\n", strcpy(arr[0], "hello world"));
exit(EXIT_SUCCESS);
}
xxxxxxxxxx
//BY SAMEERAZ
#include<stdio.h>
#include<conio.h>
void main(){
char string[50];
clrscr();
printf("ENTER STRING:");
gets(s);//gets is basically used as scanf();
printf("TYPED STRING:%s",string);
getch();
}
xxxxxxxxxx
// C program to illustrate strings
#include <stdio.h>
#include <string.h>
int main()
{
// declare and initialize string
char str[] = "Geeks";
// print string
printf("%s\n", str);
int length = 0;
length = strlen(str);
// displaying the length of string
printf("Length of string str is %d", length);
return 0;
}
xxxxxxxxxx
1. char str[] = "GeeksforGeeks";
2. char str[50] = "GeeksforGeeks";
3. char str[] = {'G','e','e','k','s','f','o','r','G','e','e','k','s','\0'};
4. char str[14] = {'G','e','e','k','s','f','o','r','G','e','e','k','s','\0'};
xxxxxxxxxx
Strings are defined as an array of characters. The difference between a
character array and a string is the string is terminated with a special
character ‘\0’.
xxxxxxxxxx
#include<stdio.h>
void main(){
int date;
char fn[50], ln[50];
printf("Enter your first name = ");
scanf("%s",&fn);
printf("Enter your last name = ");
scanf("%s",&ln);
printf("Enter your year of birth = ");
scanf("%d",&date);
printf("Your first name = %s\nlast name = %s\nand year of birth = %d", fn, ln, date);
}