I cant seem to get the output from my string in the different block. Is it normal?
If it is, is there any other way to get the output in the different block with it?
I cant seem to get the output from my string in the different block. Is it normal?
If it is, is there any other way to get the output in the different block with it?
It's hard to say without seeing your code.
What do you mean by 'block' ?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I’m told that cursive brackets meant for block.
These are the codes kind of similar to my assignment.
Code:#include <stdio.h> int main() { { char filling[] = "Kaya"; } printf("I have chosen %s\n",filling); return 0; }
Well yes, that isn't going to work.
Scope (computer science) - Wikipedia
For each variable reference, the compiler works it's way back up the chain of nested scope blocks.Code:#include <stdio.h> char msg[] = "Unused"; int main() { char msg[] = "hello"; { char msg[] = "world"; printf("Msg=%s\n",msg); // The one at line 8 } printf("Msg=%s\n",msg); // The one at line 6 return 0; }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Is there any other way that I can assign name to my variables across blocks?
Because my assignment acquires me to make an order details after making the choice
Why do you want to do that in the first place? Why not declare your variables near where you intend to use them?Originally Posted by Syazzz
If you're not sure what I mean, show your code and we could tell you how to better structure it. For example, quite obviously your example code in post #3 could have been written without the unnecessary inner code block:
Code:#include <stdio.h> int main() { char filling[] = "Kaya"; printf("I have chosen %s\n",filling); return 0; }It may well be that you should declare the necessary variables before both pieces of code. Or perhaps these pieces of code are in different functions, in which case you need to declare appropriate parameters and pass corresponding arguments.Originally Posted by Syazzz
Last edited by laserlight; 11-01-2020 at 06:45 PM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
> Is there any other way that I can assign name to my variables across blocks?
They're called functions.
Code:void foo ( char *msg ) { strcpy(msg,"hello"); } int main() { char msg[10] = ""; foo(msg); printf("Msg=%s\n",msg); return 0; }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.