3 Replies - 313 Views - Last Post: 04 October 2012 - 02:28 PM Rate Topic: -----

#1 miked89  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 04-October 12

Updating a char array address with an int value

Posted 04 October 2012 - 02:08 PM

Hello friends!

I am very new to C and I am struggling with an error that I am guessing is pretty simple but I just don't understand it.

the error is this : incompatible types in assignment


char s[STORAGE];

//parse function

void parse()
{
int c;


do {   //collect words from prompt until c = special case '&' or EOF, '/n', ';'

          
c =getword(s);   //my getword function returns an int of the size of the word. 

//i want to update the address of the char array with the size +1 for \0 so that i dont overwrite
// the array

s = s + c + 1;   //this is where the error lies 

}while ( *s != '&' ||  c != -1 || c != 0);
      



Is This A Good Question/Topic? 0
  • +

Replies To: Updating a char array address with an int value

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4142
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

Re: Updating a char array address with an int value

Posted 04 October 2012 - 02:13 PM

You probably should be passing your array into the function and not using a global variable. If you don't know how to pass a variable into a function you may want to study the links in my signature.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6078
  • View blog
  • Posts: 23,550
  • Joined: 23-August 08

Re: Updating a char array address with an int value

Posted 04 October 2012 - 02:26 PM

Explain exactly what you're trying to do here.
Was This Post Helpful? 0
  • +
  • -

#4 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1086
  • View blog
  • Posts: 4,564
  • Joined: 09-June 09

Re: Updating a char array address with an int value

Posted 04 October 2012 - 02:28 PM

You cannot change the address of an array, that is a big difference between arrays and pointers. To accomplish what you are doing, create a pointer to the array and then you can change where that points to.

i.e.
char arr[] = "Hello";
char *ptr = arr; //ptr points to address targeting 'H'

ptr++; //ptr points to address targeting 'e'
ptr+=1; //ptr points to address targeting 'l'
ptr = arr; //point to address targeting 'H'



This post has been edited by jjl: 04 October 2012 - 02:29 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1