Mp470 0 Posted April 6, 2017 Report Share Posted April 6, 2017 Olá a todos eu tenho que criar um jogo RPG de texto em C. Então eu resolvi usar uma função para escrever o texto com Sleep, porem a função escreve o texto e mais do que deveria. Como eu Conserto isso?. Meu código é esse: #include <stdio.h> #include <stdlib.h> #include<windows.h> int main() { char textogame(char text[100]); textogame("Hello world"); return 0; } char textogame(char text[100]){ int i; for(i=0;i<=text;i++){ printf("%c", text); Sleep(1000); } } Quote Link to post Share on other sites
0 vangodp 0 Posted April 7, 2017 Report Share Posted April 7, 2017 #include <stdio.h> #include <stdlib.h> #include<windows.h> int main() { char textogame ( char text[100] ); textogame ( (char*)"Hello world" ); return 0; } void textogame ( char text[100] ) { int i; for ( i = 0; text[i] != '\0'; i++ ) { printf ( "%c", text[i] ); if( text[i] != ' ' ) Sleep ( 1000 ); } } Lembre que toda string tem o caracter '\0' que indica o fim da palavra/frase, em teoria vc deve imprimir por enquanto text for diferente a '\0'. E uma modificação que acho mais atraente é pausar somente quando a letra for diferente de um espaço. if( text[i] != ' ' ) Sleep ( 1000 ); Quote Link to post Share on other sites
Question
Mp470 0
Olá a todos eu tenho que criar um jogo RPG de texto em C. Então eu resolvi usar uma função para escrever o texto com Sleep, porem a função
escreve o texto e mais do que deveria. Como eu Conserto isso?.
Meu código é esse:
#include <stdlib.h>
#include<windows.h>
{ char textogame(char text[100]);
textogame("Hello world");
}
int i;
for(i=0;i<=text;i++){
printf("%c", text);
Sleep(1000);
}
Link to post
Share on other sites
1 answer to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.