|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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;
}
|
|
#3
|
|||
|
|||
|
Scorpions4ever...thanks for helping. Can you or anyone tell me about the different "return 1" and "return -1"?
|
|
#4
|
||||
|
||||
|
>> 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! |
|
#5
|
|||
|
|||
|
thanks for explaning to me. It's very helpful
|
|
#6
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Please help Stack Valiadation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|