Crazyluigi Posted October 1, 2009 at 11:43 AM Report Share #289498 Posted October 1, 2009 at 11:43 AM Boas!! Estou com um problema pois queria eliminar um caracter numa string introduzida por teclado sendo também o utlizador a introduzir o caracter. void main() { char car; char pal[DIM]; char palm[DIM]; int i,j; printf(" Insira um caracter : "); scanf("%c",&car); printf(" Insira uma linha de texto :"); scanf("%s",&pal); j=strlen(pal); for(i=0; i<=j; i++) { if (pal[i]!=car) palm[i]=pal[i]; else { palm[i]=pal[i+1]; } } puts(palm); getche(); esta versão já elimina o caracter mas fico com uma repetição de caracter seguinte... Link to comment Share on other sites More sharing options...
Crazyluigi Posted October 1, 2009 at 11:54 AM Author Report Share #289501 Posted October 1, 2009 at 11:54 AM Não existe uma função que elimina as repetições? Link to comment Share on other sites More sharing options...
Ferreira Posted October 1, 2009 at 12:15 PM Report Share #289504 Posted October 1, 2009 at 12:15 PM Tens de "recuar" a string a partir dessa posição para que os caracteres se sobreponham aos da string original. http://twitter.com/ferreira Link to comment Share on other sites More sharing options...
Crazyluigi Posted October 1, 2009 at 02:17 PM Author Report Share #289519 Posted October 1, 2009 at 02:17 PM 1º não consegui ver bem o que estavas a dizer com o recuar pois já tinha tentado... mas depois tive mais uma pequena ajuda e tá feito!!! #include<stdio.h> #include<conio.h> #include<string.h> #define DIM 30 void main() { char car; char pal[DIM]; char palm[DIM]; int i,j, k=0; printf(" Insira um caracter : "); scanf("%c",&car); printf(" Insira uma linha de texto :"); scanf("%s",&pal); j=strlen(pal); for(i=0; i<=j; i++) { if (pal[i]!=car) palm[k]=pal[i]; else { palm[k]=pal[i+1]; k--; } k++; } puts(palm); getche(); Eis o resultado final!! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now