Example #1
0
// Show Main Menu
int main_menu(int argc, char *argv[]) {
    char main_menu_char;
    printf("\n----------------------------------------------------\n");
    printf(" What do you want to do?");
    printf("\n----------------------------------------------------\n");
    printf("\na) interact with the Fortune Cookie Server\nb) interact with the encryption/decryption server\nc) quit\n");
    printf("\n----------------------------------------------------\n\n");

    scanf("%s", &main_menu_char);
    
    getchar();
    
    switch (tolower(main_menu_char)) {
        case 'a':
        fortune_cookie();
        break;
        case 'b':
        encryption_decryption();
        break;
        case 'c':
        quick_exit();
        break;
        default :
        printf("\nPlease enter either a or b or c.\n");
        break;
    }
    
    return 1;
}
Example #2
0
void testHub()
{
    int x = 4;
    printf("x lives at %p\n", &x);
    printf("x lives at %li\n", &x);
    int *address_of_x = &x;
    int value_stored = *address_of_x;
    printf("Address of x: %p, value stored: %i\n", address_of_x, value_stored);
    printf("Address of pointer: %p\n", &address_of_x);

    *address_of_x = 99;
    printf("New stored value: %i\n", x);

    char quote[] = "Cookies make you fat";
    printf("The quote stored in %p\n", quote);
    printf("quote length: %i\n", sizeof(quote));
    int *p = quote;
    int *q = p;
    printf("q's address: %p\n", q);
    // quote = q; // Error!
    fortune_cookie(quote);

    drinks();

    char *msg_from_amy = "Don't call me";
    skip(msg_from_amy);

    pointerAddress();
}
Example #3
0
File: array.c Project: clsera/CLab
int main()
{
	char quote[] = "hello, world!";
	printf("Size of quote[]: %li\n", sizeof(quote));
	printf("The quote string is stored at: %p\n", quote);

	fortune_cookie(quote);

	return 0;
}
Example #4
0
int main() {
    int lon = -64, lat = 32,*ptrLon;
    ptrLon = &lon;
    char cook[] = "Hello Cookie";
    go_south_east(&lon,&lat);
    
    printf("lon: %i , lat: %i, ptrLon: %p\n", lon, lat,ptrLon);
    printf("lon&: %p\n",&lon);
    
    fortune_cookie(cook);
    printf("@: %p\n",cook);
    return 0;
}
int main()
{
	/* Variables are allocated storage in memory. */
	
	/* Local variables live in the stack. */ 

	/* x is stored in the stack */
	int x = 4;
  printf("x is stored at %p\n", &x);
	
	/* Global variables live in the globals section. */
	/* y is a global variable. see above. */
	printf("y is stored at %p\n", &y);
	
	/* Let's set sail. */
	int latitude = 32;
  int longitude = -64;
  go_south_east(latitude, longitude);
	/* Arrr! We haven't moved. */
  printf("Avast! Now at: [%i, %i]\n", latitude, longitude);
	
	printf("x lives at %p\n", &x);

	/* Pointers are just variables that store memory addresses.  */
  /* The & operator finds the address of a variable.  */

	/* Get the address of x */
	int *address_of_x = &x;
	printf("address_of_x = %p\n", address_of_x);
	
	/* The * operator can read the contents
      of a memory address.
  */
	/* Read the contents of an address. */
	int value_stored = *address_of_x;
	printf("read address_of_x contents = %i\n", value_stored);
	
	/* The * operator can also set the
      contents of a memory address.
  */ 
	/* Change the contents of an address. */
	*address_of_x = 99;
	int new_value_stored = *address_of_x;
	printf("read address_of_x contents after change = %i\n", new_value_stored);

	/* Wind in the sails now, cap'n! */
	fix_go_south_east(&latitude, &longitude);
  printf("Avast! Now at: [%i, %i]\n", latitude, longitude); 

  char quote[] = "Cookies make you fat";
  fortune_cookie(quote);

  /* The sizeof operator returns the
      space taken by a piece of data.
  */
	/* You can also call sizeof for a data
      type, such as sizeof(int).
  */
  printf("size of int = %i\n", sizeof(int));
	printf("size of string = %i\n", sizeof("Turtles!"));
	
	/* The array variable points to the first 
      element in the array. 
  */
  printf("The quote string is stored at: %p\n", quote);
	printf("The quote string stored: %i bytes of data\n", sizeof(quote));
	printf("The quote string stored: %s at location %i\n", quote[sizeof(quote) - 1], sizeof(quote));

  int contestants[] = {1, 2, 3};
  int *choice = contestants;
  contestants[0] = 2;
  contestants[1] = contestants[2];
  contestants[2] = *choice;
  printf("I'm going to pick contestant number %i\n", contestants[2]);

	char s[] = "How big is it?";
  char *t = s;
	
	/* sizeof is different for array and 
      pointer variables. 
  */
	printf("size of s = %i\n", sizeof(s));
  printf("size of t = %i\n", sizeof(t));
	
	int doses[] = {1, 3, 2, 1000};
	 /* An array variable can be used as a pointer. */ 
	/* ...but array variables are not quite the same. */
  printf("Issue dose %i\n", 3[doses]);
	/* doses[3] == *(doses + 3) == *(3 + doses) == 3[doses] */

  int drinks[] = {4, 2, 3};

	printf("1st order: %i drinks\n", drinks[0]);
  printf("1st order: %i drinks\n", *drinks);
	
	printf("3rd order: %i drinks\n", drinks[2]);
  printf("3rd order: %i drinks\n", *(drinks + 2));

  char *msg_from_amy = "Don't call me!";
  skip(msg_from_amy);

  int nums[] = {1, 2, 3};
  printf("nums is at %p\n", nums);
  printf("nums + 1 is at %p\n", nums + 1);

  /* Array variables can't point to
      anything else.
  */
  /* This will give a compile error. */
  /* s = t; */
	
	char name[40];
  printf("Enter your name: ");
	scanf("%39s", name);
	
	int age;
  printf("Enter your age: ");
  scanf("%i", &age);

	


	return 0;
}
Example #6
0
int main()
{
  fortune_cookie("Cookies make you fat ");
  return 1;
}