Mudanças entre as edições de "PRG29003-2022-1-02"

De MediaWiki do Campus São José
Ir para navegação Ir para pesquisar
(Criou página com '<code> #include <stdio.h> #include <string.h> int main(){ char alfa[50]="alo mundo cruel !!"; int i,j,tam,first; first=0; i=0; j=0; while (alfa[i]!='\...')
 
Linha 1: Linha 1:
<code>
+
<syntaxhighlight lang=c>  
 
#include <stdio.h>
 
#include <stdio.h>
 
#include <string.h>
 
#include <string.h>
Linha 29: Linha 29:
 
   return 0;
 
   return 0;
 
}
 
}
</code>
+
</syntaxhighlight>

Edição das 10h17min de 7 de abril de 2022

 
#include <stdio.h>
#include <string.h>

int main(){
   char alfa[50]="alo   mundo cruel  !!";
   int i,j,tam,first;
  
   first=0;
   i=0;
   j=0;
   while (alfa[i]!='\0') {
       if (alfa[i]!=' ') {
          alfa[j] = alfa[i]; /* regra geral - copia */
          j++; 
          first=1;
       } else if (first==1){
            alfa[j] = alfa[i]; /* copia */
            first=0;
            j++;
       }
       i++;
   }
   if (j!=0 && alfa[j-1] == ' ')
      alfa[j-1]='\0';
   else
      alfa[j]=0;
   printf("string: %s\n", alfa);     
   return 0;
}