C Programming (Help)

+1 Robert Summers · September 7, 2014
So when I run this code, what I expect to get turns out differently: 

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int array[] = {"First, Second, Third, Fourth"};
    printf("The names in the array are %i, %i, %i and %i", array[0], array[1], array[2], array[3]);

    return 0;
}


I get an output of: 


The names in the array are 160989014, 0, 1445432336 and 32767
Process returned 0 (0x0)   execution time : 0.024 s
Press ENTER to continue.


__________________________________________________________________________________________


Why is this, what am i doing wrong. Your help in return is greatly appreciated, Thank you. 

Post a Reply

Replies

Oldest  Newest  Rating
0 Robert Summers · September 25, 2014
What do you mean, char is spelt char and i have defined 4 chars %c %c %c %c. I'm confused. 
0 George Williams · September 13, 2014
Last time I checked, char was one letter..or did C get an update all of a sudden?
0 Robert Summers · September 13, 2014
I still cannot figure this out, maybe I might try again after I have more knowledge with C

Thanks for the help in advance.
0 Robert Summers · September 8, 2014
Nope this has not done anything. 

Thanks anyway. 
0 Tommy Phan · September 8, 2014
you can change the int return value to a string by just changing the %i to %s, and i think you should be good to go
0 Robert Summers · September 7, 2014
So the code is now written


#include <stdio.h>
#include <stdlib.h>

int main()
{
    char array[] = "First, Second, Third, Fourth";
    printf("The names in the array are %c, %c, %c and %c", array[0], array[1],       array[2], array[3]);

    return 0;
}


My output is:

The names in the array are F, i, r and s
Process returned 0 (0x0)   execution time : 0.016 s
Press ENTER to continue.
-1 Robert Summers · September 7, 2014
So how can I change the interger to a string? 
  • 1

C

106,972 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator