Skip to content

Instantly share code, notes, and snippets.

@tedwardd
Created July 10, 2016 18:35
Show Gist options
  • Save tedwardd/a739d4a08db927390def6c79cbcd8e49 to your computer and use it in GitHub Desktop.
Save tedwardd/a739d4a08db927390def6c79cbcd8e49 to your computer and use it in GitHub Desktop.
Sample C demo
#include <stdio.h>
int main(int argc, char *argv[])
{
int i = 0;
// go through each string in argv
// why am I skipping argv[0]?
for (i = 1; i < argc; i++) {
printf("arg %d: %s\n", i, argv[i]);
}
// let's make our own array of strings
char *states[] = {
"California", "Oregon",
"Washington", "Texas"
};
int num_states = 5;
for(i = 0; i < num_states; i++) {
if(states[i]) {
//int a = i + 1;
//printf("state %d: %s\n", a, states[i]);
printf("state %s\n", states[i]);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment