Skip to content

Instantly share code, notes, and snippets.

@ivanelson
Created December 17, 2018 14:27
Show Gist options
  • Save ivanelson/4108ba2ad97e04350522112a5c372a94 to your computer and use it in GitHub Desktop.
Save ivanelson/4108ba2ad97e04350522112a5c372a94 to your computer and use it in GitHub Desktop.
Vetor em "C" usando for e while
#include <stdio.h>
int main() {
char str[10] ; /*reserva espa‡o para 11 caracteres*/
int i;
printf("\nDIGITE Um nome qualquer: ");
gets(str);
i = 0;
printf("\nVou exibir usando a estrutura while: ");
while (str[i] != '\0') { // Ultimo caractere de uma string eh sempre '/0'
printf("\n%c", str[i]);
i++;
}
printf("\nVou exibir usando a estrutura for: ");
for (i =0; i<10; i++) {
printf("\n%c", str[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment