Home > Back-end >  Chain list of % c does not output data problem
Chain list of % c does not output data problem

Time:09-22

//design algorithm of the first chain series' ab 'to' xyz '
# include & lt; stdio.h>
# include & lt; Stdlib. H>
# define OK 1
# define the ERROR 0
Typedef struct Lnode {
Char data;
Struct Lnode * next;
} Sq.

Sq * Create (int n) {
Sq * s, * p, * q; int i;
S=(Sq) * malloc (sizeof (Sq));
P=s;
S - & gt; Next=NULL;
for (i=0; i Q=(Sq) * malloc (sizeof (Sq));
Printf (" please enter the first number: % d \ n ", I + 1);

The scanf (" % s ", & amp; Q - & gt; data); C to//% % s run

getchar();
Q - & gt; Next=NULL;
p-> Next=q;
P=q;
}
return s;
}


//Sq * Create (char [] a) {
//Sq * s, * p, * q; int i;
//s=(Sq) * malloc (sizeof (Sq));
//p=s;
//s - & gt; next=NULL;
//for (I=0; A [I]!='\ 0'; I++) {
//q=(Sq) * malloc (sizeof (Sq));
//q - & gt; data=https://bbs.csdn.net/topics/a [I];
//q - & gt; next=NULL;
//p - & gt; Next=q;
//p=q;
//}
//return s;
//}

Int change (Sq * s) {
Sq * p * q;
P=s - & gt; next;
While (p) {
If (p - & gt; 'a' data=https://bbs.csdn.net/topics/=& amp; & p-> Next - & gt; Data=https://bbs.csdn.net/topics/='b') {
p-> Data='https://bbs.csdn.net/topics/x'.
p-> Next - & gt; Data='https://bbs.csdn.net/topics/y'.
Q=(Sq) * malloc (sizeof (Sq));
Q - & gt; Data='https://bbs.csdn.net/topics/z'.
Q - & gt; Next=p - & gt; Next - & gt; next;
p-> Next - & gt; Next=q;
Return OK;
}
The else
P=p - & gt; next;
}
if (! P) return the ERROR;
}

Void Print (Sq * s) {
Sq * p;
P=s - & gt; next;
While (p) {
Printf (" % c ", p - & gt; data);
P=p - & gt; next;
}
printf("\n");
}
Void main () {
Sq * s; int n; char a[20];
Printf (" both please enter the number: \ n ");
The scanf (" % d ", & amp; N);
If (n & lt;=0) printf (" ERROR!" );
The else {
S=the Create (n);
//gets (a);
//s=the Create (a);
Printf (" replace front: \ n ");
Print (s);
if (! Change (s))
Printf (" did not conform to the requirements of! \n");
The else {
Printf (" after the replacement: \ n ");
Print (s);
}
}
}


Create my control characters in string is % c not as output data, % s can be output, what is the problem?

CodePudding user response:

 Sq * s; int n; char a[20]; 
Printf (" both please enter the number: \ n ");
The scanf (" % d ", & amp; N);
Getchar ()//-- -- -- -- -- - the carriage return shielding here -- -- -- -- -- -- -- -- -- -- -- --
If (n & lt;=0) printf (" ERROR!" );

CodePudding user response:

Please refer to the "c + + fflush () function and rewind () function." "

CodePudding user response:

'ABC' no such character, only the string "ABC", a character is a byte, 'ABC' is the three characters,

If the string is judgment, consider this:
 typedef struct Lnode {
Char data [20].
Struct Lnode * next;
} Sq.
  • Related