Click here to Skip to main content
13,796,858 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
hi I have to write a program in c language without string functions that gets a string and 3 numbers . for example the string is "abcdefghi" and you enter the 1st number 3 , the 2nd number that's your destination 5 and then the 3rd number 7 , the program should give you "abfcdeghi" ,its like cut and paste !

What I have tried:

well I haven't tried anything yet ! i don't even know how to start :(
Posted 11-Nov-17 0:38am
Updated 11-Nov-17 14:47pm
Comments
Suvendu Shekhar Giri 11-Nov-17 6:57am
   
Not clear what you are trying to do here!
First try something and clearly describe what you are trying to do here.

What those inputs 3,5,7 have to do with the result?
The only difference I can see is the position "f" changed to 3rd from 6th.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Think about the steps you need to take in order to achieve this:
How do you read the characters and where do you save them?
How do you read the numbers and where do you save them?
How do you find the characters from the given numbers?
How do you move characters from one position to another, without destroying the existing ones (e.g. copy, move ...)?
How do you print the results?

Write things out on paper and see what happens at each step.
  Permalink  
Comments
Member 13515388 11-Nov-17 7:54am
   
I have tried this but I still have problem with how to paste the characters :(
Richard MacCutchan 11-Nov-17 8:17am
   
Yo have two possibilities. One, you just switch two characters so "abcdef" becomes "abcfed", which is quite simple. Two, you need to remove a character from one position and insert it at another, so "abcdef" becomes "acdebf". The second form is done by removing the first character and moving the following ones down one space. Then moving some characters up one space to insert the saved character. As I said above, draw it out on paper in little boxes to help visualise what you need to do.
Member 13515388 11-Nov-17 9:45am
   
thanks a lot :)
Member 13515388 11-Nov-17 9:53am
   
#include<stdio.h>
int main()
{
char a[50],b[50];
int f,c,d,i=0,j=0;
printf("reshte morede nazar ra vared konid :\t");
gets(a);
printf("ebteda :\t");
scanf("%d",&f);
printf("enteha :\t");
scanf("%d",&c);
printf("maghsad :\t");
scanf("%d",&d);
for(i=0;a[i]!='\0';i++){
if(f<=i && i<=c){
b[j]=a[i-1];
j++;
}
}


this is my program till now ! it cuts a part of my string and it pastes it in another string , now i wanna copy the b[j] in a[c] ! like a[50] is abcdefghi and i enterd f=3 , c=5 and d=7 then it cuts cde and move it in b[j] now i want it to show cde in g place but idk how
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Input is : "abcdefghi"
result is: "abfcdeghi"
and you have 3 numbers 3, 5 and 7.

First thing: you need to understand what are those numbers, because to move 1 letter in a string, you need only 2 numbers: starting and ending positions.

After that, you need to figure out how go to get wanted result.
As programmer, your job is to create algorithms, we don't do it for you, it is your homework.

We do not do your HomeWork.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.181207.3 | Last Updated 11 Nov 2017
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100