strcpy in c code example
Example 1: struct in C
#include<stdio.h>
#include<string.h>
struct Student{
long int rollNo;
int age;
char name[50];
int totalMarks;
};
int main(){
struct Student s1;
s1.rollNo = 1232234643;
s1.age = 10;
char s[]="Jonathan";
strcpy(s1.name,s);
s1.totalMarks = 450;
printf("RollNumber: %d \nName: %s \nTotal Marks: %d",s1.rollNo,s1.name,s1.totalMarks);
return 0;
}
Example 2: strcpy in C
#include <stdio.h>
#include <string.h>
int main() {
char str1[20] = "C programming";
char str2[20];
strcpy(str2, str1);
puts(str2);
return 0;
}
Example 3: strcpy
#include <stdio.h>
#include <string.h>
int main ()
{
char str1[]="Sample string";
char str2[40];
char str3[40];
strcpy (str2,str1);
strcpy (str3,"copy successful");
printf ("str1: %s\nstr2: %s\nstr3: %s\n",str1,str2,str3);
return 0;
}
Example 4: strcmp c
string a = "words";
string b = "words";
if (strcmp(a, b) == 0)
{
printf("a and b match");
}
else
{
printf("a and b don't match");
}
Example 5: what is stdin in c
Example 6: strcpy en c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char Temp[255];
strcpy(&Temp,"Gladir");
strcpy(&Temp,"ABC");
strcpy(&Temp,"Gladir.com");
puts(&Temp);
return 0;
}