Need help with char arrays

hey all
I can't figure out how to get this working : / if anyone could help it'd be appriciated :)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <cstdlib>
#include <cctype>

using namespace std;

void read_array(char, int&);
void write_array(const char, int);

const int MAXSIZE = 20;


int main(void) {
    
    char digit_array[MAXSIZE];
    int size, i;
    
    size = 0;
    cout << "Enter an integer that is at most 20 digits: ";
    read_array(digit_array[i], size);
    write_array(digit_array[i], size);
    
    return 0;
}

void read_array(char d_array[], int& size) {
    char digit;
    
    do {
        cin.get(digit);
        if(isdigit(digit)) {
            d_array[size] = digit;
            size++;
        } 
    }while (size < 20 && isdigit(digit));
}

void write_array(const char d_array[], int size) {
    cout << "The integers you entered are: ";
    for (int i = 0; i < size; i++) {
        cout << d_array[i] << endl;
    }
}
first I would fix your declaration of read_array/write_array since it doesn't match the actual function.

void read_array(char[], int &);
void write_array(const char[], int);

-> You forgot the []. also, I prefer to use * instead of [], but it's just semantics at that point as both do the same thing.
Thanks, works now :)) i appreciate it
was such an easy solution haha
Topic archived. No new replies allowed.