I am new to writing code, so please briefly explain your answers so I can (try to) keep up, thanks! I am attempting to input a string, assign the string to an array of chars, and to selectively extract a portion of said char string to return (ie input "character" and return "act"), and I cannot seem to understand why I keep getting the error "subscripted value is neither array nor pointer nor vector". Here is my code:
#include <stdio.h>
char source[81], result[81];
int start, count;
char substring ();
int main(void)
{
substring ("character", 4, 3, result);
printf ("%s", result); //print result
return 0;
}
char substring (source, start, count, result)
{
int i = 0;
while (i <= (count-1))
{
result[i] = source[((start-1)+i)]; //op chosen chars to result array
++i;
if (i == count)
{
result[i] = '\n'; //when i = count, insert null at end of source array
}
}
return result;
}
When I attemp to compile, I get the error: "
Compilation error time: 0 memory: 0 signal:0
prog.c: In function ‘substring’:
prog.c:20:13: error: subscripted value is neither array nor pointer nor vector
result[i] = source[((start-1)+i)]; //op chosen chars to result array
^
prog.c:20:25: error: subscripted value is neither array nor pointer nor vector
result[i] = source[((start-1)+i)]; //op chosen chars to result array
^
prog.c:24:14: error: subscripted value is neither array nor pointer nor vector
result[i] = '\n'; //when i = count, insert null at end of source array
^"