0% found this document useful (0 votes)
30 views

Compro2 String Removing and String Functions

This C program code defines a function to remove characters from a string by taking user input for the string, position from where to remove characters, and number of characters to remove. It then shifts the characters from that position to the end of the string to remove the specified number of characters and prints the modified string.

Uploaded by

redssakti
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Compro2 String Removing and String Functions

This C program code defines a function to remove characters from a string by taking user input for the string, position from where to remove characters, and number of characters to remove. It then shifts the characters from that position to the end of the string to remove the specified number of characters and prints the modified string.

Uploaded by

redssakti
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Maringka Rodney

Compro 2-Paralel A String-removing characters && string functions

1. #include <stdio.h>
2. #include <string.h>
3. int main()
4. {
5. int i,n,p,k;
6. char a[100];
7.
8. printf("Enter the String without space: ");
9. scanf("%s", a);
10. printf("Enter position: ");
11. scanf("%d",&p);
12.
13. printf("\nEnter number of characters: ");
14. scanf("%d",&n);
15. k=p+n-1;
16. i=0;
17. for (i=p-1; i<strlen(a)-n;i++){
18. a[i]=a[k++];
19. }
20. a[i]='\0';
21. printf("string after removing character/characters: %s ",a);
22.
23.
24. return 0;
25.}
#include<stdio.h>
#include<string.h>
int main(){
char nama[20];
char temp[20];
printf("masukkan nama kata/kalimat: ");
gets(nama);
printf("hasil copy: %s\n",strcpy(temp,nama));

printf("hasil reverse: %s\n",strrev(temp));

printf("hasil compare: %d\n",strcmp(temp,nama));


printf("\npanjang string: %d\n", strlen(nama));
printf("ganti ke huruf besar: %s\n",strupr(nama));
printf("ganti lagi ke huruf kecil: %s\n",strlwr(nama));

if (strcmp(temp,nama)==0){
printf("\n%s adalah palindrom\n",nama);
printf("\ncoba gabung: %s\n", strcat(temp,nama));
}
else printf("%s bukanlah palindrom",nama);

return 0;
}

You might also like