To declare char[] as input/output parameter instead of String in C

Asked 2 years ago, Updated 2 years ago, 42 views

Hi, how are you?

I am a returning student who is suffering from forgetting everything because I didn't use C and C++ after being discharged from the military.

I was asked to write a replacement password in C, but it would have been okay if it was Java because I used it while working, but it's painful because the professor told me to do it in C.

It's so hard because I can't use the class and string in C, but there are a lot of grammar errors when I try to use char[] like Java's String. Is there a way to write or replace char[] as the input/output parameter value of the function?

 

Nothing is done, but I'm uploading the code just in case.

#include <stdio.h>

char[] enterKeyValue(void){
    char key[]; // declaration of key table

    printf("Enter key values. Numbers, space, and special letters are not allowed.\n"); // Willingness to make you re-enter numbers, spaces, or special characters when they come in

    printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ \n");
    printf("|||||||||||||||||||||||||| \n");
    printf("vvvvvvvvvvvvvvvvvvvvvvvvvv \n");
    scanf_s("%s \n", &key, sizeof(key));

    return key;
}
char[] en (char[] key table, char[] sentence to encrypt) {
    // Encryption
    return encrypted sentence;
}
char[] dec (char[] key table, char[] sentence to be decrypted) {
    // Decryption
    return 복호화시킨문장;
}
char[] keyCheck(char testValid[]){
    // Make sure that the key value is exactly 26 digits
    // Check key values for numbers, spaces, and special characters
    // Check for duplicate key values
    // All alphabets in the key value are capitalized for now
    return correct key;
}

int main(){
    char key[]; // declaration of key table
    int doFunction = 1; // C is dissatisfied with why there is no bullion, but temporary bullion variable created temporarily

    while(doFunction == 1){
        key = enterKeyValue();
        key = keyCheck(key);

        // Encryption or decryption
        enc(); // Encryption
        dec(); // decryption

        // I don't know if I'll do it again
        If (again) continue;
        else doFunction = 0;
    }

    return 0;
}

c string array

2022-09-21 18:34

1 Answers

intenc(char[] key table, char[] sentence to be encrypted, char[] decrypted sentence)

It should be declared as follows.

Instead of allocating memory to heap within the function, it should be done externally and processed by passing his pointer.

If the key table is an unchanged value, such as a constant, you can also leave it as a global variable/constant.

And the bowl is provided in c99.

https://en.wikipedia.org/wiki/C_data_types#stdbool.h


2022-09-21 18:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.