So how would I go about getting the string length,basically what I'm trying to do is write a recursive program that takes a number from user and then prints those numbers out vertically recursively. I'm just getting junk in my output but I thought I could do it this way without going into anything to crazy. Well this is what I have so far, basically in a char array I can use strlen to get the length of the string up to the terminating character, how would I do this for integers?
Code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int vertPrint(int array[5], int length);
int main()
{
int array[5], length=0;
printf("Enter in a String of Numbers to Print Vertically");
scanf("%s", &array);
vertPrint(array, length);
}
int vertPrint(int array[5], int length)
{
static int i = 0;
if (i < length+1){
printf("%d\n", array[i]);
i++;
return (vertPrint(array, length));
}
else
return;
}
ignore the fact that I took out the code for length, I did that when I posted it on here as I had used length= sizeof(array) but that isn't going to work