0
This code I’m using to study C, is not converting (at least it’s what I think) a INT temp10 to CHAR... appearing an error:
line 5: 5182 Segmentation failure (recorded core image)
What can it be?
int main() {
// aqui esta tudo OK!
char tempA[100] = "11";
printf("COUVE = %s\n", tempA);
strcpy(tempA, "22");
printf("CEREJA = %s\n", tempA);
strcpy(tempA, "kk");
outraFuncao(tempA);
// mas se transformo um int em string:
temp6 = 1000;
temp7 = 100;
temp8 = 10;
temp9 = 1;
temp10= temp6+temp7+temp8+temp9;
char temp10=temp10+'0';
printf("\n\n\n");
// da falha de segmentacao na hora do print
printf("CEREJA2 = %s\n", temp10);
// aqui vai ser importante para meu programa... chamar um funcao com esse valor convertido de int para char
// mas o mesmo erro defalha desegmentacao acontece..
outraFuncao(temp10);
}
void outraFuncao(char *temp) {
// strcpy(temp, "33");
printf("AMORA = %s\n", temp);
}
This code doesn’t make any sense, so it’s hard to start helping. There’s nothing converting anything. I don’t even know if you need it. There’s a lot that doesn’t need to be there. Actually the whole code doesn’t do anything very useful. It doesn’t even serve as an exercise. Besides you seem to ignore what’s said, so it gets complicated.
– Maniero
The question is, why convert something if you can already use what you want directly? I didn’t even try to answer because it will only solve your problem without teaching you anything useful. What’s the point of giving you the solution to this, if what you’re doing is all wrong? I don’t know what the goal is, but this code doesn’t help to learn anything. I don’t know if you got to do this somewhere. I know you need to do it differently or ask questions that will really help you.
– Maniero
I suggest doing as Joseph X said, take a book and start learning structurally. Maybe even start with easier language. Normally I usually indicate starting with C even though almost everyone is against it. But there are cases and cases. C is a language full of detail. With meaningless "exercises" you will not learn. You need something that will guide you, that will present each concept, one at a time, in the right order, things that have relevance.Then doing the exercises suggested in the book will have doubts and it will be + easy to ask here.I’m afraid this code is + harming learning
– Maniero
Another possibility is to look for a good course, I do not know if you have in your city. When you’re lost, one-on-one guided help is important.I’m trying to show you that this path adopted is not going to help you, you need to opt for another form of learning. Be careful with easy and cheap options (such as tutors and videos on the internet), they hurt more than help.
– Maniero
thanks for the attention, but I do not wish to disturb you any more, I already approved an answer. Let’s leave it for there.
– Roberval Sena 山本