How to correctly pass an array to struct [closed]











up vote
-2
down vote

favorite












Question Edited



I'm very new in C, and here.



Is it possible for an array return its value via a struct?



Although I'm trying to process each character in List[5] = {1, 2, 3, 4}, however, it only sticks at 1 and only prints 575757 rather than



My struct



struct Count numbers() {                                    
struct Count numbers;
int List[5] = {1, 2, 3, 4};
int i = 0;

for (i = 0; i < 10; i++) { //It might be something in my for loop
numbers.intOne= List[i] + 4; // 1 + 4
numbers.intTwo= List[i] + 6; // 1 + 6
return numbers;
}
};


This only prints 575757, i wish this to print 576879



void printCode(struct Count numbers) {
int i;
for (i = 0; i < 3; i++) {
printf("%i%i", numbers.intOne, numbers.intTwo);

}
}


The main



int main() {
int i = 0;

for (i = 0; i < 10; i++) {
numbers();
printCode(numbers());
getchar();
}

}


Thank you for any help!










share|improve this question















closed as unclear what you're asking by Antti Haapala, tripleee, Lundin, ewolden, Makyen Nov 19 at 10:16


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • What do you mean by "string", perhaps you're forgetting that a string is an array of characters instead of an array of integers.
    – Antti Haapala
    Nov 19 at 6:52






  • 1




    Also you return on the first iteration of for loop which makes the loop totally meaningless
    – Antti Haapala
    Nov 19 at 6:53








  • 1




    "It only stucks at '4352'." => move the return statement out of the loop.
    – Antti Haapala
    Nov 19 at 7:12










  • What string? What do you mean "couldn't pass the value [20]"? This is very unclear, what are you trying to do?
    – Lundin
    Nov 19 at 8:39










  • @Lundin i'm trying to make the string goes to another code, which is the '3615' in Code[20]
    – origamimagician
    Nov 19 at 9:47

















up vote
-2
down vote

favorite












Question Edited



I'm very new in C, and here.



Is it possible for an array return its value via a struct?



Although I'm trying to process each character in List[5] = {1, 2, 3, 4}, however, it only sticks at 1 and only prints 575757 rather than



My struct



struct Count numbers() {                                    
struct Count numbers;
int List[5] = {1, 2, 3, 4};
int i = 0;

for (i = 0; i < 10; i++) { //It might be something in my for loop
numbers.intOne= List[i] + 4; // 1 + 4
numbers.intTwo= List[i] + 6; // 1 + 6
return numbers;
}
};


This only prints 575757, i wish this to print 576879



void printCode(struct Count numbers) {
int i;
for (i = 0; i < 3; i++) {
printf("%i%i", numbers.intOne, numbers.intTwo);

}
}


The main



int main() {
int i = 0;

for (i = 0; i < 10; i++) {
numbers();
printCode(numbers());
getchar();
}

}


Thank you for any help!










share|improve this question















closed as unclear what you're asking by Antti Haapala, tripleee, Lundin, ewolden, Makyen Nov 19 at 10:16


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • What do you mean by "string", perhaps you're forgetting that a string is an array of characters instead of an array of integers.
    – Antti Haapala
    Nov 19 at 6:52






  • 1




    Also you return on the first iteration of for loop which makes the loop totally meaningless
    – Antti Haapala
    Nov 19 at 6:53








  • 1




    "It only stucks at '4352'." => move the return statement out of the loop.
    – Antti Haapala
    Nov 19 at 7:12










  • What string? What do you mean "couldn't pass the value [20]"? This is very unclear, what are you trying to do?
    – Lundin
    Nov 19 at 8:39










  • @Lundin i'm trying to make the string goes to another code, which is the '3615' in Code[20]
    – origamimagician
    Nov 19 at 9:47















up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











Question Edited



I'm very new in C, and here.



Is it possible for an array return its value via a struct?



Although I'm trying to process each character in List[5] = {1, 2, 3, 4}, however, it only sticks at 1 and only prints 575757 rather than



My struct



struct Count numbers() {                                    
struct Count numbers;
int List[5] = {1, 2, 3, 4};
int i = 0;

for (i = 0; i < 10; i++) { //It might be something in my for loop
numbers.intOne= List[i] + 4; // 1 + 4
numbers.intTwo= List[i] + 6; // 1 + 6
return numbers;
}
};


This only prints 575757, i wish this to print 576879



void printCode(struct Count numbers) {
int i;
for (i = 0; i < 3; i++) {
printf("%i%i", numbers.intOne, numbers.intTwo);

}
}


The main



int main() {
int i = 0;

for (i = 0; i < 10; i++) {
numbers();
printCode(numbers());
getchar();
}

}


Thank you for any help!










share|improve this question















Question Edited



I'm very new in C, and here.



Is it possible for an array return its value via a struct?



Although I'm trying to process each character in List[5] = {1, 2, 3, 4}, however, it only sticks at 1 and only prints 575757 rather than



My struct



struct Count numbers() {                                    
struct Count numbers;
int List[5] = {1, 2, 3, 4};
int i = 0;

for (i = 0; i < 10; i++) { //It might be something in my for loop
numbers.intOne= List[i] + 4; // 1 + 4
numbers.intTwo= List[i] + 6; // 1 + 6
return numbers;
}
};


This only prints 575757, i wish this to print 576879



void printCode(struct Count numbers) {
int i;
for (i = 0; i < 3; i++) {
printf("%i%i", numbers.intOne, numbers.intTwo);

}
}


The main



int main() {
int i = 0;

for (i = 0; i < 10; i++) {
numbers();
printCode(numbers());
getchar();
}

}


Thank you for any help!







c string for-loop struct






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 20:20

























asked Nov 19 at 5:56









origamimagician

12




12




closed as unclear what you're asking by Antti Haapala, tripleee, Lundin, ewolden, Makyen Nov 19 at 10:16


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by Antti Haapala, tripleee, Lundin, ewolden, Makyen Nov 19 at 10:16


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • What do you mean by "string", perhaps you're forgetting that a string is an array of characters instead of an array of integers.
    – Antti Haapala
    Nov 19 at 6:52






  • 1




    Also you return on the first iteration of for loop which makes the loop totally meaningless
    – Antti Haapala
    Nov 19 at 6:53








  • 1




    "It only stucks at '4352'." => move the return statement out of the loop.
    – Antti Haapala
    Nov 19 at 7:12










  • What string? What do you mean "couldn't pass the value [20]"? This is very unclear, what are you trying to do?
    – Lundin
    Nov 19 at 8:39










  • @Lundin i'm trying to make the string goes to another code, which is the '3615' in Code[20]
    – origamimagician
    Nov 19 at 9:47




















  • What do you mean by "string", perhaps you're forgetting that a string is an array of characters instead of an array of integers.
    – Antti Haapala
    Nov 19 at 6:52






  • 1




    Also you return on the first iteration of for loop which makes the loop totally meaningless
    – Antti Haapala
    Nov 19 at 6:53








  • 1




    "It only stucks at '4352'." => move the return statement out of the loop.
    – Antti Haapala
    Nov 19 at 7:12










  • What string? What do you mean "couldn't pass the value [20]"? This is very unclear, what are you trying to do?
    – Lundin
    Nov 19 at 8:39










  • @Lundin i'm trying to make the string goes to another code, which is the '3615' in Code[20]
    – origamimagician
    Nov 19 at 9:47


















What do you mean by "string", perhaps you're forgetting that a string is an array of characters instead of an array of integers.
– Antti Haapala
Nov 19 at 6:52




What do you mean by "string", perhaps you're forgetting that a string is an array of characters instead of an array of integers.
– Antti Haapala
Nov 19 at 6:52




1




1




Also you return on the first iteration of for loop which makes the loop totally meaningless
– Antti Haapala
Nov 19 at 6:53






Also you return on the first iteration of for loop which makes the loop totally meaningless
– Antti Haapala
Nov 19 at 6:53






1




1




"It only stucks at '4352'." => move the return statement out of the loop.
– Antti Haapala
Nov 19 at 7:12




"It only stucks at '4352'." => move the return statement out of the loop.
– Antti Haapala
Nov 19 at 7:12












What string? What do you mean "couldn't pass the value [20]"? This is very unclear, what are you trying to do?
– Lundin
Nov 19 at 8:39




What string? What do you mean "couldn't pass the value [20]"? This is very unclear, what are you trying to do?
– Lundin
Nov 19 at 8:39












@Lundin i'm trying to make the string goes to another code, which is the '3615' in Code[20]
– origamimagician
Nov 19 at 9:47






@Lundin i'm trying to make the string goes to another code, which is the '3615' in Code[20]
– origamimagician
Nov 19 at 9:47














1 Answer
1






active

oldest

votes

















up vote
1
down vote














it only stucks at '4352'




You are returning from decode soon after processing the first element of the output array which is 4352. So the other elements of check and param arrays do not get filled up.



In any case, check and param are arrays local to the decode function and the values of their elements cannot be used outside the function.






share|improve this answer























  • That's incorrect, rest of the elements are initialized as if by assigned 0.
    – Antti Haapala
    Nov 19 at 6:49










  • Sorry, split is uninitialized.
    – Antti Haapala
    Nov 19 at 6:53










  • Yes, the answer is incorrect. But is split not being initialized in the for loop?
    – P.W
    Nov 19 at 7:10










  • ah it is, I saw only that there were some xors and stuff. It makes even less sense now.
    – Antti Haapala
    Nov 19 at 7:11










  • @AnttiHaapala: Updated the answer. But don't know if it is really useful. Will wait for a while for confirmation from OP and delete the answer if not useful.
    – P.W
    Nov 19 at 7:22


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote














it only stucks at '4352'




You are returning from decode soon after processing the first element of the output array which is 4352. So the other elements of check and param arrays do not get filled up.



In any case, check and param are arrays local to the decode function and the values of their elements cannot be used outside the function.






share|improve this answer























  • That's incorrect, rest of the elements are initialized as if by assigned 0.
    – Antti Haapala
    Nov 19 at 6:49










  • Sorry, split is uninitialized.
    – Antti Haapala
    Nov 19 at 6:53










  • Yes, the answer is incorrect. But is split not being initialized in the for loop?
    – P.W
    Nov 19 at 7:10










  • ah it is, I saw only that there were some xors and stuff. It makes even less sense now.
    – Antti Haapala
    Nov 19 at 7:11










  • @AnttiHaapala: Updated the answer. But don't know if it is really useful. Will wait for a while for confirmation from OP and delete the answer if not useful.
    – P.W
    Nov 19 at 7:22















up vote
1
down vote














it only stucks at '4352'




You are returning from decode soon after processing the first element of the output array which is 4352. So the other elements of check and param arrays do not get filled up.



In any case, check and param are arrays local to the decode function and the values of their elements cannot be used outside the function.






share|improve this answer























  • That's incorrect, rest of the elements are initialized as if by assigned 0.
    – Antti Haapala
    Nov 19 at 6:49










  • Sorry, split is uninitialized.
    – Antti Haapala
    Nov 19 at 6:53










  • Yes, the answer is incorrect. But is split not being initialized in the for loop?
    – P.W
    Nov 19 at 7:10










  • ah it is, I saw only that there were some xors and stuff. It makes even less sense now.
    – Antti Haapala
    Nov 19 at 7:11










  • @AnttiHaapala: Updated the answer. But don't know if it is really useful. Will wait for a while for confirmation from OP and delete the answer if not useful.
    – P.W
    Nov 19 at 7:22













up vote
1
down vote










up vote
1
down vote










it only stucks at '4352'




You are returning from decode soon after processing the first element of the output array which is 4352. So the other elements of check and param arrays do not get filled up.



In any case, check and param are arrays local to the decode function and the values of their elements cannot be used outside the function.






share|improve this answer















it only stucks at '4352'




You are returning from decode soon after processing the first element of the output array which is 4352. So the other elements of check and param arrays do not get filled up.



In any case, check and param are arrays local to the decode function and the values of their elements cannot be used outside the function.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 at 7:21

























answered Nov 19 at 6:26









P.W

8,4852540




8,4852540












  • That's incorrect, rest of the elements are initialized as if by assigned 0.
    – Antti Haapala
    Nov 19 at 6:49










  • Sorry, split is uninitialized.
    – Antti Haapala
    Nov 19 at 6:53










  • Yes, the answer is incorrect. But is split not being initialized in the for loop?
    – P.W
    Nov 19 at 7:10










  • ah it is, I saw only that there were some xors and stuff. It makes even less sense now.
    – Antti Haapala
    Nov 19 at 7:11










  • @AnttiHaapala: Updated the answer. But don't know if it is really useful. Will wait for a while for confirmation from OP and delete the answer if not useful.
    – P.W
    Nov 19 at 7:22


















  • That's incorrect, rest of the elements are initialized as if by assigned 0.
    – Antti Haapala
    Nov 19 at 6:49










  • Sorry, split is uninitialized.
    – Antti Haapala
    Nov 19 at 6:53










  • Yes, the answer is incorrect. But is split not being initialized in the for loop?
    – P.W
    Nov 19 at 7:10










  • ah it is, I saw only that there were some xors and stuff. It makes even less sense now.
    – Antti Haapala
    Nov 19 at 7:11










  • @AnttiHaapala: Updated the answer. But don't know if it is really useful. Will wait for a while for confirmation from OP and delete the answer if not useful.
    – P.W
    Nov 19 at 7:22
















That's incorrect, rest of the elements are initialized as if by assigned 0.
– Antti Haapala
Nov 19 at 6:49




That's incorrect, rest of the elements are initialized as if by assigned 0.
– Antti Haapala
Nov 19 at 6:49












Sorry, split is uninitialized.
– Antti Haapala
Nov 19 at 6:53




Sorry, split is uninitialized.
– Antti Haapala
Nov 19 at 6:53












Yes, the answer is incorrect. But is split not being initialized in the for loop?
– P.W
Nov 19 at 7:10




Yes, the answer is incorrect. But is split not being initialized in the for loop?
– P.W
Nov 19 at 7:10












ah it is, I saw only that there were some xors and stuff. It makes even less sense now.
– Antti Haapala
Nov 19 at 7:11




ah it is, I saw only that there were some xors and stuff. It makes even less sense now.
– Antti Haapala
Nov 19 at 7:11












@AnttiHaapala: Updated the answer. But don't know if it is really useful. Will wait for a while for confirmation from OP and delete the answer if not useful.
– P.W
Nov 19 at 7:22




@AnttiHaapala: Updated the answer. But don't know if it is really useful. Will wait for a while for confirmation from OP and delete the answer if not useful.
– P.W
Nov 19 at 7:22



Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin