The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Please help Stack Valiadation
Discuss Please help Stack Valiadation in the C Programming forum on Dev Shed. Please help Stack Valiadation C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 7th, 2002, 10:20 AM
|
|
Registered User
|
|
Join Date: Sep 2002
Posts: 21
Time spent in forums: 1 h 52 m 59 sec
Reputation Power: 0
|
|
|
Please help Stack Valiadation
hi....i know how to do "pop" and "push" for my stack program. But i can't get my validation right. I hope someone can help me on this. Thank you ^_^
This is what i want to do:
int valid(char k[], int p)
check the array containing o characters.
return true if array has only spaces, digits, or operators
otherwise return false
|

September 7th, 2002, 12:40 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
Are you looking for something like this:
Code:
#include <ctype.h>
int valid(char k[], int p) {
register int i;
char c;
if (p == 0)
return 0;
for (i = 0; i < p; i++) {
c = k[i];
if ((!isdigit(c)) && (c != ' ') && (c != '+')
&& (c != '-') && .... rest of operators ... )
return 0;
}
return 1;
}
|

September 7th, 2002, 08:26 PM
|
|
Registered User
|
|
Join Date: Sep 2002
Posts: 21
Time spent in forums: 1 h 52 m 59 sec
Reputation Power: 0
|
|
|
Scorpions4ever...thanks for helping. Can you or anyone tell me about the different "return 1" and "return -1"?
|

September 7th, 2002, 09:22 PM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
>> Can you or anyone tell me about the different "return 1" and "return -1"?
It entirely depends on the function(s) you are calling. For instance, I used a library of functions a long time ago, that would return 1 on success and negative numbers on failure. The value of the negative number would indicate what the specific cause of failure was. So you could write code like this:
Code:
int result;
result = some_func();
if (result > 0) {
/* Do something useful
} else {
/* Determine the cause of failure from the return value */
switch (result) {
case -1:
printf ("OS Error: Could not open blah");
break;
case -2:
printf("Phase of moon error");
break;
...
}
}
Then again, these return values depended entirely upon the author of those functions. You can invent your own return values for your functions. Traditionally though, most functions in C usually return a number to indicate success and 0 to indicate failure (though there are significant exceptions like strcmp() in which the meaning of the return values are reversed!). Other functions may return positive numbers to indicate success codes and negative numbers to indicate error codes.
Hope this helps!
|

September 8th, 2002, 01:50 AM
|
|
Registered User
|
|
Join Date: Sep 2002
Posts: 21
Time spent in forums: 1 h 52 m 59 sec
Reputation Power: 0
|
|
|
thanks for explaning to me. It's very helpful
|

September 8th, 2002, 05:16 AM
|
|
Registered User
|
|
Join Date: Sep 2002
Posts: 21
Time spent in forums: 1 h 52 m 59 sec
Reputation Power: 0
|
|
Scorpions4ever...or anyone...I just inserted that code wiht my program. But i got all the errors and warnings popping up.
it's getting frustrated. I hope someone can help me to check my code. If i have your email, i'll send it to you. Because this code it's too long to put it here.
Thank you
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|