#include<stdio.h> #include<conio.h> main() { clrscr(); char *str; int ind,pos,nw=0; printf("\nEnter string: "); gets(str); printf("Enter position of character you want to delete(start with 0): "); scanf("%d:,&pos); for (ind=0;str[ind]!='\0';ind++) { if (ind!=pos) { str[nw]=str[ind]; nw++; } } str[nw-1]='\0'; printf("%s",str); getch(); return 0; }
This is my code for the program that deletes a character from a string.
#include<stdio.h> #include<conio.h> main() { clrscr(); char *str,nwch; int ind,pos,nw=0; printf("\nEnter string: "); gets(str); printf("\nEnter character you want to insert: "); nwch=getchar(); printf("\nEnter position where you want to insert new character(start with 0): "); scanf("%d",&pos); for (ind=0;str[ind]!='\0';ind++) //sorry got a typo here XD { if (ind!=pos) { str[nw]=str[ind]; nw++; } else if (ind==pos) { str[nw]=nwch; nw++; } } printf("\n%s",str); getch(); return 0; }
my codes for the character program insertion
.....my character deleting program works just fine...and the insertion program is just its opposite twin...problem is my insertion program doesnt work the way i want it to

but it doesnt

any advise from the masters?and yea this has to be done in turbo c using old fashion looping

This post has been edited by yuuske: 03 September 2009 - 05:40 AM