English 中文(简体)
替换线。 结果——随机符号线
原标题:Can t replace the lines. Result - line of random symbols

我在大学中担负着一项任务,要求我进入两条线路,然后取而代之。

我非常感谢,如果我在那里犯错的话。 bad。 ——

P.S.:这项任务也要求我写上方案,同时写上职能,而不是职能。 因此,在我把我的守则划分为职能之前,它正按需要开展工作。

#include <stdio.h>
#include <string.h>
#include <malloc.h>

int entstr1(char *, int long1);
int entstr2(char *, int long2);
int plustr(char*, char*, char*, int, int, int);
int i;
int longall, long1, long2;

int main(void) {
    char str1[7], str2[7], rstr[14];;

    

    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);

    entstr1(str1, long1);
    entstr2(str2, long2);

    printf("%s", str1);
    printf("%s", str2);

    longall = long1 + long2;
    printf("
%d", longall); // 

    plustr(str1, str2, rstr, longall, long1, long2);
    printf("

Result line: %s", rstr);

    return 0;

}

int entstr1(char *str1, int long1) {
    
    printf("Enter 1 line: ");
    fgets(str1, sizeof str1, stdin);
    fflush(stdin);
    long1 = strlen(str1);
    printf("
Length of 1 line: %d
", long1); //

    return 1;
}

int entstr2(char* str2, int long2) {

    printf("Enter 1 line: ");
    fgets(str2, sizeof str2, stdin);
    fflush(stdin);
    long2 = strlen(str2);
    printf("
Length of 2 line: %d
", long2); //

    return 1;
}

int plustr(char* str1, char* str2, char* rstr, int longall, int long1, int long2) {

    for (i = longall-1, long1; i > long2; i--, long1--) {
        rstr[i] = str1[long1];
    }
    for (i = long2; i != 0; i--) {
        rstr[i] = str2[i];
    }
    return 1;
}

我增加了几个试样,看看“一刀”是否具有不良价值,因此! IDK 因此,它变成了0,但第1和第2号指挥表明,1和2号长时期具有正确的价值,但随后,在两项变量中,当它再次履行主要职能时,它变成了0个。

问题回答

页: 1 我想知道,我的法典是否充分执行你的想法。 检查是否正确? 然后,我在必要时解释。 但就你而言,你是好的法典,在看到这一法典时不需要任何解释。

这里是:

#include <stdio.h>
#include <string.h>

#define MAX_LENGTH 7

int entstr1(char *, int *long1);
int entstr2(char *, int *long2);
int plustr(char *, char *, char *, int, int, int);

int main(void) {
    char str1[MAX_LENGTH], str2[MAX_LENGTH], rstr[MAX_LENGTH * 2];
    int longall, long1, long2;

    entstr1(str1, &long1);
    entstr2(str2, &long2);

    printf("%s", str1);
    printf("%s", str2);

    longall = long1 + long2;
    printf("
%d", longall);

    plustr(str1, str2, rstr, longall, long1, long2);
    printf("

Result line: %s", rstr);

    return 0;
}

int entstr1(char *str1, int *long1) {
    printf("Enter 1 line: ");
    fgets(str1, MAX_LENGTH, stdin);
    fflush(stdin);
    *long1 = strlen(str1) - 1; // Adjust for the newline character
    printf("
Length of 1 line: %d
", *long1);

    return 1;
}

int entstr2(char *str2, int *long2) {
    printf("Enter 2 line: ");
    fgets(str2, MAX_LENGTH, stdin);
    fflush(stdin);
    *long2 = strlen(str2) - 1; // Adjust for the newline character
    printf("
Length of 2 line: %d
", *long2);

    return 1;
}

int plustr(char *str1, char *str2, char *rstr, int longall, int long1, int long2) {
    for (int i = 0; i < long1; i++) {
        rstr[i] = str1[i];
    }

    for (int i = 0; i < long2; i++) {
        rstr[long1 + i] = str2[i];
    }

    rstr[longall] =   ; // Null-terminate the result string

    return 1;
}

This is my result:

“enterography

Hope to be helpful.





相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签