The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Solaris 10 Patch Return Code 1; what does it mean debd SUN Solaris 4 05-08-2008 07:29 AM
Solaris 8 installed but bash is not working bluridge SUN Solaris 2 01-24-2008 01:03 PM
Solaris 10 - init stops working GKnight SUN Solaris 0 05-07-2007 08:04 PM
Prtdiag is Not working in Solaris 8 Ver sure.solaris SUN Solaris 7 01-26-2007 01:37 PM
/usr/bin/cut not working with largefiles on Solaris 10 wottie SUN Solaris 1 04-04-2006 02:57 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-08-2006
Registered User
 

Join Date: Jun 2004
Posts: 13
Angry Code working AIX 5.2 and not in Solaris 5.9

Hi,
When i run the below code in AIX it runs and solaris not ... why ???

#include <stdio.h>
#include <string.h>
#define MAX 1

int main ()
{
char str[] ="1,2,3,4,5";
char * pch,b[MAX];
int a;
printf ("Enter the int to be searched [%s]",str);
scanf("%d",&a);
sprintf(b,"%d",a);
pch = strtok (str,",");
while (pch != NULL)
{
if(!strcmp(pch,b))
/*printf ("%s\n",pch);*/
printf("found");
pch = strtok (NULL, ",");
}
}

Output :
Solaris : NIL
AIX: found
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-08-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,573
right now i dont have access to an IBM node,

and in solaris,

herez the code:

Code:
#include <stdio.h>
#include <string.h>
#define MAX 1

int main ()
{
char str[] ="1,2,3,4,5";
char * pch,b[MAX + 1];
int a;
printf ("Enter the int to be searched [%s]",str);
scanf("%d",&a);
sprintf(b,"%d",a);
b[MAX]='\0';
pch = strtok (str,",");
while (pch != NULL)
{
if(!strcmp(pch,b))
{
  printf("found");
  break;
}
pch = strtok (NULL, ",");
}
}
you had made use of strcmp - to compare two strings ( here a string and a char array )
but the char array is not terminated,
hold a value and termination value.
Reply With Quote
  #3 (permalink)  
Old 08-08-2006
Registered User
 

Join Date: Jun 2004
Posts: 13
Thanks buddy
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0