Home > Back-end >  [introduction to the c language problem] novice pointer used are not ripe, thank you.
[introduction to the c language problem] novice pointer used are not ripe, thank you.

Time:06-02

Title:
One day (or day! A few foreign friends to visit the elder brother, but sound elder brother once can't meet so many people at the same time, so he wanted to put the names of all the foreign friends (Jane, there is only one word, for example: Mike) according to the dictionary order, in order to determine the order of meet,

Enter
Each test case input to a line, including a number of foreign friends Jane (each Jane name only a word, and not more than 10 letters), is no more than 100 foreign friends to visit brother,

O
In dictionary order of foreign friends Jane sorting, output the result of the sort, name with a space between phase separation, each output to a line,

The sample input
Michael KangKang HangMeiMei LiLei
Sample output
HangMeiMei KangKang LiLei, Michael

CodePudding user response:

Get an array of char STR [1100].
Gets to read a line to STR, and then put the string according to the blank space split in an array, the array sorting, compare the size with STRCMP function, output

Write their own code

Pointers are not familiar with, just can be used to practice

CodePudding user response:

Fun
reference 1 floor response:
get an array of char STR [1100].
Gets to read a line to STR, and then put the string according to the blank space split in an array, the array sorting, compare the size with STRCMP function, output

Write their own code

Pointers are not familiar with, just can be used to practice

My code is always in the input data after press the return key without output, do you know why?

CodePudding user response:

Paste the code to see just know
In general is in a infinite loop or wait for you continue to enter the state that is no response

CodePudding user response:

Fun
reference 3 floor response:
post code to see just know
In general is in a infinite loop or wait for you to continue the input state is so no response


#include
#include
Int main ()
{
Char a [100] [10].
Int I, k, j, num=0, count=0;
For (I=0;; I++)
{
The scanf (" % s ", a [I]);
If (a [I]==' ')
{
Num=I;
break;
}
}
for(i=0; i{
k=i;
for(j=i+1; JIf (STRCMP (a [k], a [j]) & gt; 0)
k=j;
If (k!=I)
{
Char \ [100].
Strcpy (temp, a [k]);
Strcpy (a [k], a [I]);
Strcpy (a [I], temp);
}
}
For (I=0;; I++)
Printf (" % s ", a [I]);
return 0;
}

CodePudding user response:

Fun
reference 3 floor response:
post code to see just know
In general is in a infinite loop or wait for you to continue the input state is so no response


If (a [I]==' ')
{
Num=I;
break;
}
I want to use this to indicate the end of the input data, it can be used, please?

CodePudding user response:

Not the scanf input string and encounter space automatic truncation, filtered out,
You can use the gets function reads a line, Spaces that can be put in, and then to judge if each character Spaces

CodePudding user response:

Fun
reference 6 floor response:
no the scanf input string and encounter space automatic truncation, filtered out,
Function reads a line, you can use the gets the space can be put in, and then to judge if each character Spaces

Ok, I will try, thank you!

CodePudding user response:

The scanf (" % s ", STR);
You enter the ABC def KDKDKD passing
STR only hold ABC three characters inside

The scanf (" % s % s ", str1, str2)
You enter the ABC def passing
Str1 is ABC
Str2 is def
Among all those Spaces to Marx, the

Str2 char str1 [100], [100].
The scanf (" % s % s ", str1, str2);
Printf (" % s \ n \ n % s ", str1, str2);
You can test yourself

CodePudding user response:

references to make fun of the eighth floor response:
the scanf (" % s ", STR);
You enter the ABC def KDKDKD passing
STR only hold ABC three characters inside

The scanf (" % s % s ", str1, str2)
You enter the ABC def passing
Str1 is ABC
Str2 is def
Among all those Spaces to Marx, the

Str2 char str1 [100], [100].
The scanf (" % s % s ", str1, str2);
Printf (" % s \ n \ n % s ", str1, str2);
You can test our


I'm sorry, but I still don't know what is the cause of the output is not in my code,
I wrote a simple code input data into the two dimensional array, then the two dimensional array of data one by one the same output, but still no output after the input data and press enter
The code is as follows:
#include
#include
Int main ()
{
Char str1 [100] [10].
Int I, count=0, num=0;
For (I=0;; I++)
{
The scanf (" % s ", str1 [I]);
If (str1 [I]==' ')
{
Num=I;
break;
}
}
for(i=0; i{
If (count==0) printf (" % s ", str1 [I]);
The else printf (" % s ", str1 [I]);
count++;
}

return 0;
}

CodePudding user response:

You can not pass this compilation STR [I] is a string, you and how do you compare a null character

For (I=0;; I++)
{
The scanf (" % s ", str1 [I]);
If (str1 [I] [0]==' ')
{
Num=I;
break;
}
Printf (" I=% d str1=% s ", I, str1 [I])
}

Never back out of the cycle, with the scanf you cannot return the Spaces

CodePudding user response:

make fun of the reference to the tenth floor response:
you compile it can not pass STR [I] is a string, you and how do you compare a null character

For (I=0;; I++)
{
The scanf (" % s ", str1 [I]);
If (str1 [I] [0]==' ')
{
Num=I;
break;
}
Printf (" I=% d str1=% s ", I, str1 [I])
}

Never back out of the cycle, with the scanf you cannot return the space


Hello, I wrote a new output code:
#include
#include
Int main ()
{
Char * p, STR [100] [10], c, a, [100].
Int I, j, count=0, num=0, com.
P=STR [0].
For (I=0;; I++)
{
j=0;
while((c=getchar())!='\ n' & amp; & c!=' ')
STR [I] [j++]=c;
If (c==' ') {STR [I] [j]='\ 0'; num++; }
Else if (c=='\ n') {STR [I] [j]='\ 0'; num++; break; }
}
for(i=0; i{
for(j=0; J{
Com=STRCMP (STR [I], STR [j]);
If (com<0)
{
Strcpy (a, STR [I]);
Strcpy (STR [I], STR [j]);
Strcpy (STR [j], a);
}
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related