Programmingpointer question in C
Posted:

Programmingpointer question in CPosted:

Yolo
  • Christmas!
Status: Offline
Joined: Jan 13, 201311Year Member
Posts: 541
Reputation Power: 28
Status: Offline
Joined: Jan 13, 201311Year Member
Posts: 541
Reputation Power: 28
so for my class we are learning pointers. have to write an some code that will display the letter of a given string along with the hex value of the letter in ascii and the address of the element of the array. My code works perfectly fine but I get a warning saying
"15 7 G:\exercise #14.c [Warning] assignment from incompatible pointer type".
Can somebody please point the problem out to me (pun intended)
heres the source code along with output.

#include <stdio.h>
#include <string.h>
int main()
{
int i;
int ascii_value;
int *ptr;
char array[99] = "hello";
for (i=0; i<strlen(array); i++)
{
ascii_value = array[i];
ptr = &array[i];
printf("letter: %c ascii hex value: %x address: %p \n", array[i], ascii_value, ptr);
}
return 0;
}

/*
letter: h ascii hex value: 68 address: 000000000062FDC0
letter: e ascii hex value: 65 address: 000000000062FDC1
letter: l ascii hex value: 6c address: 000000000062FDC2
letter: l ascii hex value: 6c address: 000000000062FDC3
letter: o ascii hex value: 6f address: 000000000062FDC4
*/
#2. Posted:
Xaldin
  • TTG Addict
Status: Offline
Joined: Oct 09, 201014Year Member
Posts: 2,358
Reputation Power: 106
Status: Offline
Joined: Oct 09, 201014Year Member
Posts: 2,358
Reputation Power: 106
try using a char* instead of an int*, not 100% sure but thats my guess since youre pointing to a char
Users browsing this topic: None
Jump to:


RECENT POSTS

HOT TOPICS