Home > Back-end >  C language errors, how to solve
C language errors, how to solve

Time:03-27

Beginner C, in the second class, do these homework substitution when met the segmentation fault, where is really don't understand the question, ask for help!!!!!!

#include
#include
#include
#include
#include

Bool isunique (const string STR []);
String substitution (string n [], string agrv [1]).

Int main (int agrc, string agrv [])
{

If (agrc!
=2){
Printf (" the Usage:./substitution key \ n ");
return 1;
}

Int length=strlen (agrv [1]).
If (length!=26)
{
Printf (" Key must contain 26 characters \ n ");
return 1;
}

If (isunique (& amp; Agrv [1]))
{
Printf (" Key must contain the company characters \ n ");
return 1;
}
for (int i=0; I & lt; 26. I++)
{
If (isalpha (agrv [1])
{
String n=get_string (" Plaintext: ");
N=substitution (& amp; N, & amp; Agrv [1]).
Printf (" Ciphertext: % s \ n ", n);
}
The else
{
Printf (" Key must contain alphabetic \ n ");
return 1;
}
}
}

Bool isunique (const string STR [])
{
Bool a, [256].
Memset (a, 0, sizeof (a));
For (int I=0, len=strlen (* STR); I & lt; Len. I++)
{
Printf (" % c \ n ", * STR [I]);

int index=* STR [I];
[can confirm here's the problem, the first run there is no problem, can correctly judge the first letter, but the second run will be submitted to the section of error, is what reason]

If (a) [index]
{
return false;
}
A [index]=true;
}
return true;
}

String substitution (string n [], string agrv [1])
{
For (int j=0, len=strlen (* n); J & lt; Len. J++)
{

Char c=* n [j];
If (isupper (c))
{
Int x=(int) c - 'A';
* n [j]=toupper (agrv [1] [x]).
}
The else
{
Int y=(int) c - 'a';
* n [j]=tolower (agrv [1] [y]);
}
}
Return * n.
}

CodePudding user response:

For (int I=0, len = strlen (* STR); I & lt; Len. i++)

CodePudding user response:

. STR [I] is not a string object? What are solutions for reference? Also assigned to int, this topic is you want to do?

CodePudding user response:

Well, the string as the type is not C language style, the building also tried * on the play, the two bad habits oh,
This program as an experience, can let the building further understand pointer, address and value,
  • Related