4 Replies - 550 Views - Last Post: 12 February 2011 - 07:05 AM Rate Topic: -----

#1 Guest_DOWmad*


Reputation:

Identifier expected and assignment makes pointer from int without cast

Posted 10 February 2011 - 03:58 PM

Hi, I am fairly new to C so compilation errors i am still trying to understand.
Two errors:
Identifier expected and assignment makes pointer from int without cast problem on this line.

	int isThere = contains("linux",x);


Any help would be appreciated, Thank you.
Is This A Good Question/Topic? 0

Replies To: Identifier expected and assignment makes pointer from int without cast

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,437
  • Joined: 23-August 08

Re: Identifier expected and assignment makes pointer from int without cast

Posted 11 February 2011 - 11:50 AM

Since this appears to be straight C, and it's posted in Objective-C, I'm moving this to C and C++.

We need more information about the exact error, the function prototype for contains, and the datatype of x.
Was This Post Helpful? 1
  • +
  • -

#3 DOWmad  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 10-February 11

Re: Identifier expected and assignment makes pointer from int without cast

Posted 12 February 2011 - 04:35 AM

Hi, sorry for the mistakes.
//contains prototype
int contains(char target[], char source[])
{
	char * x = strstr(source, target);
	if(x != NULL) return 1;
	else return 0;
}



These two are within the main method in a for loop.
x is of type int.
	int isThere = contains("linux", x); 


Thanks.

This post has been edited by DOWmad: 12 February 2011 - 04:36 AM

Was This Post Helpful? 0
  • +
  • -

#4 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: Identifier expected and assignment makes pointer from int without cast

Posted 12 February 2011 - 04:48 AM

If x is an int, how can you pass it to a char source[] parameter ?
Was This Post Helpful? 2
  • +
  • -

#5 DOWmad  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 10-February 11

Re: Identifier expected and assignment makes pointer from int without cast

Posted 12 February 2011 - 07:05 AM

A fair point...that was embarrassing. Thank you :)
Ok, so i switched the line to this,

	char isThere = contains("linux", char * x); 


This removes the pointer problem. Just an identifier to fix.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1