TP Vecteurs
Vecteur de caractères
Structure
#include <stdio.h> #include <stdlib.h> #define MAXC 200 typedef struct vecchar { int nbc; char v [MAXC]; } vecchar_t; |
fonction de remplissage
vecchar_t remplirv (int nb) { vecchar_t v; int i; char c; if (nb >= MAXC) exit(9); v.nbc = nb; v.v[0] = 'J'; v.v[1] = 'e'; v.v[2] = ' '; v.v[3] = 'f'; v.v[4] = 'a'; v.v[5] = 'i'; v.v[6] = 's'; v.v[7] = ' '; v.v[8] = 's'; v.v[10] = 'o'; v.v[11] = 'u'; v.v[12] = 'v'; v.v[13] = 'e'; v.v[14] = 'n'; v.v[15] = 't'; v.v[16] = ' '; v.v[17] = 'c'; v.v[18] = 'e'; v.v[19] = ' '; v.v[20] = 'r'; v.v[21] = 'e'; v.v[22] = 'v'; v.v[23] = 'e'; v.v[24] = ' '; v.v[25] = 'e'; v.v[26] = 't'; v.v[27] = 'r'; v.v[28] = 'a'; v.v[29] = 'n'; v.v[30] = 'g'; v.v[31] = 'e'; v.v[32] = ' '; v.v[33] = 'e'; v.v[34] = 't'; v.v[35] = ' '; v.v[36] = 'p'; v.v[37] = 'e'; v.v[38] = 'n'; v.v[39] = 'e'; v.v[40] = 't'; v.v[41] = 'r'; v.v[42] = 'a'; v.v[43] = 'n'; v.v[44] = 't'; v.v[45] = '\n'; v.v[46] = 'd'; v.v[47] = '\''; v.v[48] = 'u'; v.v[49] = 'n'; v.v[50] = 'e'; v.v[51] = '\n'; c = '@'; for (i = 52; i < nb; i++) { c = c + 1; v.v[i] = c; if (c=='Z') c = '`'; if (c=='z') c = '@'; } return v; } |
void affvc (vecchar_t v) { int i; for (i = 0; i < v.nbc; i++) printf("%c",v.v[i]); printf("\n"); } |
Exercices