Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void fun1()
- {
- char one[10] = "whoareyou";
- printf("%s \n", one);
- one[4] = '\0';
- printf("%s \n", one);
- }
- void fun2()
- {
- char two[7] = "mustang";
- char three[4] = "dog";
- char four[4] = "cat";
- printf("%s\n", two);
- }
- void fun3()
- {
- char one[2];
- char two[8] = "mustang";
- char three[4] = "dog";
- one[0] = 'a';
- one[1] = 'b';
- printf("%s\n", one);
- }
- void fun4()
- {
- char two[12] = "mustangherd";
- two[7] = '\0';
- two[5] = two[9];
- two[6] = two[10];
- printf("%s\n", two);
- }
- void fun5()
- {
- char howdy[] = "hello";
- char snoopy[6];
- char linus[5] = "linus";
- char lucy[7] = "lucy";
- int i;
- printf("%s\n", howdy);
- printf("%s\n", lucy);
- printf("Enter a string: ");
- scanf("%s", snoopy);
- printf("%s\n", snoopy);
- printf("-------");
- for (i=0; i<3; i++)
- {
- printf("%c", snoopy[i]);
- }
- printf("\n");
- /* lucy = "person"; wont' compile */
- printf("%s\n", linus);
- }
- void fun9()
- {
- /* Surprisingly, the Hanly textbook doesn't explain that the
- * compiler is smart enough to figure out how big of an array
- * to allocate for a string */
- char pres[] = "Barack Obama";
- char greet[4] = "hi!";
- printf("The president is: ");
- printf("%s %s\n", pres,greet);
- }
- int main(void)
- {
- fun1();
- fun2();
- fun3();
- fun4();
- fun5();
- fun9();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement