I'm working on a personal project to learn C. The first part of it is to parse a user-prompted line of integers separated by white spaces and read it into an array of integers. Here's what I have:
#include <stdio.h>
#include <string.h>
#define MAX_PAGES 100
int main() {
char *pageInputArray;
int *pages[MAX_PAGES];
char *start;
char *end;
int iterVar;
printf("%s\n", "Enter the page reference stream: ");
scanf("%s", pageInputArray);
start = pageInputArray[0];
iterVar = 0;
while ((start = strpbrk(start, "0123456789") != NULL) && (iterVar < MAX_PAGES)) {
pages[iterVar] = strtol(start, &end, 0);
printf("%d\n", pages[iterVar]);
start = end;
iterVar++;
}
}
And when I try to complile I get this warning:
warning: assignment makes pointer from integer without a cast [enabled by default]
For the lines which have:
start = pageInputArray[0];
and
while ((start = strpbrk(start, "0123456789") != NULL) && (iterVar < MAX_PAGES)) {
and
pages[iterVar] = strtol(start, &end, 0);
It's driving me crazy because it seems that the machine thinks @start is an integer, but I'm clearly declaring it as a char* . Can someone tell me what's going on and how to fix it?