I am newbie in C and have some doubts in my code.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
void TypeText(char text[]){
for (int i=0; i<=strlen(text); i++)
{
printf("%c", text[i]);
sleep(1);
}
}
int main(){
TypeText("This is the year 2086...");
return 0;
}
I'm trying to create a typing effect and I thought this code should work very well. It should print one string of the text per second, however its shows the whole text after 24s (24 is the size of my text). I realized that if put a "\n" in the printf it works how it should, although I wouldn't want to skip a line in every string
printf("%c\n", text[i]);
I am using the last version of Ubuntu
Thank anyone who can help me