use C program Write a function to copy all the characters in the input string t starting from the m-th character to the string s.call this function in main. void strmcpy( char *t, int m, char *s ); The strmcpy function copies all characters starting from the m-th character in the input string char * t to the string char * s. If m exceeds the length of the input string, the resulting string should be an empty string. [Example of input]: 7 happy new year [Sample output]: new year
时间: 2024-03-18 10:39:38 浏览: 350
Here's the C program that meets your requirements:
```c
#include <stdio.h>
#include <string.h>
void strmcpy(char *t, int m, char *s);
int main() {
char input[100];
int m;
char output[100];
printf("Enter a string and an integer m: ");
scanf("%[^\n]%*c %d", input, &m);
strmcpy(input, m, output);
printf("Resulting string: %s\n", output);
return 0;
}
void strmcpy(char *t, int m, char *s) {
int start_index = m - 1;
int len = strlen(t);
if (start_index >= len) {
s[0] = '\0';
return;
}
int i;
for (i = start_index; i < len; i++) {
s[i - start_index] = t[i];
}
s[i - start_index] = '\0';
}
```
The `strmcpy` function takes in three parameters: a pointer to the input string `t`, an integer `m`, and a pointer to the output string `s`. It then copies all characters starting from the `m`-th character in `t` to `s`. If `m` exceeds the length of `t`, an empty string is returned.
In `main`, the user inputs a string and an integer `m`, and the `strmcpy` function is called with these parameters. The resulting string is then printed to the console.
I hope this helps!
阅读全文