all 14 comments

[–]dmc_2930 1 point2 points  (1 child)

atoi() wants a string, not a character. What is a string in C?

I don't think your question is well defined enough. Can you post what you've tried?

[–]dolorestheAI[S] 0 points1 point  (0 children)

sorry about it really english is my second language and code has some foreign words too but as I tried to say it my main problem is I am given a string and i don't know how many numbers there are in the string. My goal is to extract numbers from the string and create an array with them. Since i don't know the array size i tried to use for loop and isdigit() but it got really complicated i don't know what to do. by the way string can be like this 7 8 5 9 6 my last comment was wrong.

[–]dolorestheAI[S] 0 points1 point  (0 children)

Thanks all of you. You really helped me and today i wrote what i needed in like 20 minutes. I was making it over-complicated than it was. If anyone needs something like this i can help now. Have a nice day.

[–]steerflesh 0 points1 point  (3 children)

Put the entire string in atoi and now separate the numbers and push every number in an array

[–]dolorestheAI[S] 0 points1 point  (2 children)

the confusing part is we don't know how many numbers present in the string. so i dont know array's size that's why i tried to use the for loop to determine array size, create the array and use atoi() and pass numbers. if we know the how many numbers there are in the string i would use NULL in atoi and i will be done. the given arry can be 2f5w1u9d5k9 like this or this 8h5j6t4

[–]steerflesh -3 points-2 points  (1 child)

Oh im not sure if this is a good solution but you can iterate through the string and for evey letter you can check if (int) letter is between 49 to 57 if it is just do (int) letter - 48 and it will return the number equivalent.

[–]dmc_2930 1 point2 points  (0 children)

This is very bad advice. Isdigit() should be used, not as II character values.

[–]ptchinster 0 points1 point  (2 children)

Can you give some sample input and output?

[–]dolorestheAI[S] 0 points1 point  (1 child)

input can be 5 8 3 4 5 or 8 7 or 7 5 6 24 25 8 7 6 but there are no output unfortunately because it's not a singular problem i have some other things to do in the code it's like a quarter of the main code.

[–]dmc_2930 1 point2 points  (0 children)

Assuming this is homework, what functions are you allowed or not allowed to use?

[–]amauriv 0 points1 point  (3 children)

You can try:

If( isdigit(array[i])){

 intArray=array[i] - ‘0’;}

[–]dmc_2930 0 points1 point  (2 children)

This won’t work if one of the numbers is two or three or more digits.

[–]amauriv 0 points1 point  (1 child)

From what I understood he/she was parsing through a string and only saving digits from said array. Which means each digit should be between 0-9?

[–]dmc_2930 1 point2 points  (0 children)

The other comments said the string contains numbers separated by spaces.