Praying C language string

Title Description

Compiling a function that returns the pointer value, find the substrings.

Entry

A first input integer n, there are n represents test data, data for each test:

1) press the prompt "input string:" Input string

2) then prompted to "i =" Qiuzi input string starting position i

3) then prompts "j =" Enter the length of the substring j

Input example (red indicates input from the keyboard)

2
input string:I am a student
i=6
j=5
input string:ab
i=3
j=2

Output Example:

a stu
Error

prompt

Reference Example 6-19.

Note that before each gets, use getchar (); read out has been previously entered in the keyboard buffer of the carriage

Code

#include <stdio.h>
#include<string.h> 
void zz(int i,int j,char*s)
{
	int p,k=0;
	if(i>strlen(s)||j>strlen(s))	
					printf("Error");
	else 
	{
		for(p=i-1;p <j+i-1;p++)
		{
			printf("%c",s[p]);
		}
	}
}

int main()
{
    char s[100];
    int n,i,j;
    scanf("%d",&n);
    while(n--)
    {
    	printf("input string:");
    	getchar();
    	gets(s);
    	
    	printf("i=");
    	scanf("%d",&i);
    	
    	printf("j=");
    	scanf("%d",&j);
    	
    	zz(i,j,s);
    	printf("\n");
    }
 	return 0;
}
Published 47 original articles · won praise 29 · views 1483

Guess you like

Origin blog.csdn.net/Qianzshuo/article/details/103758798