strings in c
#include
#include
#include
#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);
}
string in c
#include
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);
}
strings in c
#include
#include
#include
#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);
}
strings in c
#include
#include
#include
#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);
}
strings in c
#include
#include
#include
#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);
}
string in c and how it works
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’.
|