Advertisement
thenewboston

C Programming Tutorial - 9 - I Need Arrays

Aug 22nd, 2014
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     char name[14] = "Bucky Roberts";
  7.     printf("My name is %s \n", name);
  8.  
  9.     // you can access individual elements by using subscripts
  10.     // in programming, all array start with 0, not 1
  11.     name[2] = 'z';
  12.     printf("My name is %s \n", name);
  13.  
  14.     // when you define an array and set its value on the same line, you don't need to say how many elements
  15.     char food[] = "tuna";
  16.     printf("I love to eat %s \n", food);
  17.  
  18.     // if you want to assign a new string to an array, you have to use strcpy()
  19.     strcpy(food, "bacon");
  20.     printf("I love to eat %s \n", food);
  21.  
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement