1
I decided to make this code simple, where I have an empty vector and a function that fills it only with a letter that the user type, but I’m not able to print.
If I wear that printf()
commented, it works, but if print out not at all. And if I try to print it in function main()
, comes out with m 2 at the end. Why?
#include <stdio.h>
#include <string.h>
#define TAM 3
void preencher(char *str, char letra){
int c;
for (c=0; c<TAM; c++){
*str = letra;
//printf("%c", *str);
*str++;
}
while (*str) printf("%c", str++);
}
int main(){
char str[TAM], letra;
scanf("%c", &letra);
preencher(&str, letra);
}