Home Forums C Programming Understanding Pointers and Strings Re: Re: Understanding Pointers and Strings

#3538
GWILouisaxwzkla
Participant

Heres how I might do this ( this uses pointer arthimatic instead of indexes ) :



#include
#include

void draw(char *w, int len);

int main()
{

char words [ 100 ] = ("This is my hundredth attept st this extremely annoying task :)");
char * index = NULL;
int len = 21;

draw( words + 11, len );



return 0;
}

void draw ( char * words, int lengthOutput ) //words points to words [ 11 ]

{

char * upperLimit; //pointer for storing upper limit of output


upperLimit = words + lengthOutput; //upperLimit points to the 32nd char of words [ 100 ]
putchar ( 'n' ); //output newline
while ( words != upperLimit ) //while not at the 32nd char of array
{
putchar ( * words); //output the current char
words ++; //goto next char in the array
}
putchar ( 'n' ); //output a newline

}