I am working on an assignment in C and am being asked to create a function that returns a status word, but I have no clue what that means and even less how to declare the return type and how the returned status word is determined. Please help.
Asked
Active
Viewed 940 times
-2
-
Maybe `char* func(){return "status word";}`? – Spikatrix Mar 26 '15 at 12:00
-
1Perhaps you should ask your instructor for clarification? – Bill Lynch Mar 26 '15 at 15:29
-
When programming, "word" typically refers to a 16 bit integer (or in some cases a larger integer than that). – Lundin Mar 26 '15 at 15:29
2 Answers
1
Сomplementing volerag's post can add such a way:
typedef enum {
FAIL,
SUCCESS
} STATUS;
STATUS getStatus() {
// ...
return ...;
}
But this doesn't make big difference.

shauryachats
- 9,975
- 4
- 35
- 48

Cargo Tan
- 43
- 3
0
A status word could be a variable (having a value) which tells about the execution of a function - whether it succeeded in doing something it was supposed to do or not.
For example:
int doSomething()
{
if (somethingCanBeDone)
return SUCCESS;
else
return FAILURE;
}
Here, SUCCESS
and FAILURE
are the status words returned from the function which tell whether the function has succeeded in the job it had to do.
You could do it in two ways.
Use a
#define
statement to define the status words.#define SUCCESS 1 #define FAILURE 0 int doSomething() { if (somethingCanBeDone) return SUCCESS; else return FAILURE; } int main() { int returnval = doSomething(); if (returnval == SUCCESS) { //Do something } else { //Do something else. } }
Use
const int
statements to define the status words.const int SUCCESS = 1; const int FAILURE = 0;
These are similar to macros, but since they tell about the status of a function, they are known as status words.

shauryachats
- 9,975
- 4
- 35
- 48