# itterations on a string, 'expression must have a pointer-to-object type' error

Stack Overflow Asked by Tom Arica on December 2, 2020

I have a problem doing itterations on a string.

function input:

1. a string of numbers with no spaces in between, in the range of [-9,9], and up to 10 numbers (means maximum 20 chars long if every number is negative).
2. the size of the string.

the function needs to create an array of the numbers.

for example if I get the input "809-2-3", my new array needs to be – [8,0,9,-2,-3].

in my code, I get the error ‘expression must have a pointer-to-object type’, and I dont understand it.

this is the code I made:


void separate_nums(char str, int str_len)
{
int new_arr[20];
int i;
for (i = 0; i <= str_len - 1; i++)//run through the string
{
if (str[i] == '-') //if the char is -, take minus of the next char. than increase index by one so youll get to the next number
{
new_arr[i] = -str[i + 1];
i++;
}
else
new_arr[i] = str[i];
}
}



Thank you!

First, an array is needed.

1. Count the number of digits (n).
2. Allocate an array which can hold n numbers.

Next, it's just a question of looking at the characters of the string one at a time. Any time a - is encountered, simply use the next character, but negate it.

1. Initialize a variable identifying the next character to parse.
2. Loop for each element of the array,
1. Assume the number isn't negative.
2. If the next character is a -,
1. The number is negative.
2. Move to the next character.
3. Convert the next digit to a number.
4. If the number should be negative,
1. Negate the number.
5. Store the number in the current array element.
6. Move to the next character.

Of course, we need to make sure the user doesn't provide garbage. This is left to you to handle.

Answered by ikegami on December 2, 2020

## Related Questions

### How to get a thread dump of a running Node.js process?

3  Asked on December 23, 2020 by philipp-claen

### Laravel does not read .env variables when there is a # character

1  Asked on December 23, 2020 by helderam

### My gdb debugger isn’t responding when I launch it

0  Asked on December 23, 2020

### Getting the purchase/consumption status of a Google Play item from C#

1  Asked on December 23, 2020 by ordineu

### Jquery Select all IDs in different Sections

1  Asked on December 23, 2020 by abcid-d

### Can’t merge two dictionaries into one dictionary

3  Asked on December 23, 2020 by yoel-regen

### What kind of errors are returned by HttpServer stream in Dart

1  Asked on December 23, 2020 by suragch

### Sharing Power BI Dashboards – External Users

1  Asked on December 23, 2020 by datageek

### SQL query to loop through records

1  Asked on December 22, 2020 by doe

### Is there a better way to implement nested setTimeouts()

1  Asked on December 22, 2020 by dashman

### Array list from AsyncData/fetch rendered by v-for throw: The client-side rendered virtual DOM tree is not matching server-rendered

2  Asked on December 22, 2020 by daniel-von-mirbach

### Next.js deploy via Serverless Framework, How does it work and can be up-to-date?

0  Asked on December 22, 2020 by ji-in-kim

### CMYK image being converted to RGB

0  Asked on December 22, 2020 by entity

### no reverse matching at / and crawler is not a registered namespace

1  Asked on December 22, 2020 by sudheer-ranjan

### Bootstrap Toast at bottom right of page

1  Asked on December 22, 2020 by sean-thorburn

### I doesn’t receive any formated data from static class

0  Asked on December 21, 2020 by asfdasfdsfdfsd

### How you create your own views that interact with existing views with operator |?

1  Asked on December 21, 2020 by omnifarious