I'm having trouble to make the following algorithm work without index (with index it works). It's a small exercise for my university, and one of the requirements is that I can only use "pointer reference" to walk through my allocated array (frase), not index. What I've tried last to make it work is commented, and I give up because anything I try doesn't work... Thanks for the help.
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
int main(){
char* frase;
frase = malloc(sizeof(char) * 100);
gets(frase);
/*
while(*frase != '\0'){
printf("%c", *frase);
frase++;
}
*/
int i = 0;
while(frase[i]){
printf("%c", toupper(frase[i]));
i++;
}
printf("\n");
free(frase);
}
freeit afterwars, as you loose the original pointer. So you'll have to save it before incrementing.while(*(frase + i))andtoupper(*(frase + i)). Change those to the ones I have written and try again :)free?