| |

VerySource

 Forgot password?
 Register
Search
View: 1044|Reply: 2

Urgent! ~~~ Design a program cuts

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-23 09:00:01
| Show all posts |Read mode
Design a program cuts that reads data from standard input and obtains data in the range defined by the first parameter n and the second parameter m. Both n and m are integers, that is, the nth is extracted from the input string. All characters between and including the m character. E.g:
$ cuts 11 14
this is a test of cuts program (type)
test (show results)
5
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-4-13 07:30:01
| Show all posts
The above question is a bit typo, it should be the following statement:
Design a program cuts, which reads data from standard input and obtains the data defined by the first parameter n and the second parameter m, n and m are integers, that is, extract the nth from the input string All characters from the character to the m-th character (including these two characters). E.g:
$ cuts 11 14
this is a test of cuts program (typing)
test (display results)
$
Reply

Use magic Report

0

Threads

6

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-4 11:45:01
| Show all posts
#include <stdio.h>
#include <string.h>
#include <malloc.h>

int main(int argc,char **argv,char **env)
{
char *src=(char *)malloc(sizeof(char)*40);
char *result=(char *)malloc(sizeof(char)*20);
The
int i=0;
int j=0;
int start=0;
int end=0;
The
printf("src=");
gets(src);
The
printf("start=");
scanf("%d",&start);
The
printf("end=");
scanf("%d",&end);

if(start>0&&start<=strlen(src)&&end >0&&end <=strlen(src))
{
i=start;
while(*src&&i<end+1)
{
The
result[j]=src[i];
j++;
i++;
}
result[j]='\0';
}
else
{
printf("input error!\n");
return 1;
}
puts(result);
free(src);
free(result);
return 0;
}

Change it yourself!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list