Home > Back-end >  [C language help] part of the single digits calculator (individual)
[C language help] part of the single digits calculator (individual)

Time:03-23

#include
#include
#include
#include //useless
Void main ()
{
{
Printf (" hw additional \ n ");
Int I, j=0, n [1000].

Char a, [1000].
Gets (a);//input string, such as: 1-2
For (int k=0;; K++)
{
If (a [k] <='9' & amp; & A [k] & gt;='0')//if the character for the digital
{

A, sscanf (" % d ", & amp; N [j]);//character can be converted to an integer

Printf (" n [% d]=% d ", j, n [j]);

j++;

}
Else if (a [k]=='\ n')//meet end enter
{
break;
}


}
}


The purpose of this code is the plus or minus, skip the input string will be digital
Characters into integer and assign n [j]

Question: should always be done only for the first time, such as input 1 to 2, then the result is: n [0]=1,
Don't know where is at the back of the 2

CodePudding user response:

Read your sscanf is a ah, is read from,

CodePudding user response:

reference 1st floor forever74 response:
your sscanf reads is a ah, that is from the beginning to read on,

Then how can I get a one-to-one into n [I] [I]?

CodePudding user response:

This sentence is changed to:
 sscanf (& amp; A [k], "% d", & amp; N [j]);//character can be converted to an integer 

CodePudding user response:

The
reference 3 floor QZJHJXJ response:
this sentence is changed to:
 sscanf (& amp; A [k], "% d", & amp; N [j]);//character can be converted to an integer 

Into the problem, I use another way to solve, the results met another bug again, super strange, look at the trouble

CodePudding user response:

The
reference 3 floor QZJHJXJ response:
this sentence is changed to:
 sscanf (& amp; A [k], "% d", & amp; N [j]);//character can be converted to an integer 

Posting, sent out

CodePudding user response:

 # include & lt; Stdio. H> 
#include
#include
#include //useless
Void main ()
{
//{
Printf (" hw additional \ n ");
Int I, j=0, n [1000].

Char a [1000], TMP [2];
Gets (a);//input string, such as: 1-2
For (int k=0;; K++)
{
If (a [k] <='9' & amp; & A [k] & gt;='0')//if the character for the digital
{
TMP [0]=a, [k]. TMP [1]='\ 0';
Printf (" TMP=% s \ n ", TMP);
Sscanf (TMP, "% d", & amp; N [j]);//character can be converted to an integer

Printf (" n [% d]=% d ", j, n [j]);
}
Else if (a [k]=='\ n')//meet end enter
{
break;
}
}

}

CodePudding user response:

refer to 6th floor QZJHJXJ response:
 # include & lt; Stdio. H> 
#include
#include
#include //useless
Void main ()
{
//{
Printf (" hw additional \ n ");
Int I, j=0, n [1000].

Char a [1000], TMP [2];
Gets (a);//input string, such as: 1-2
For (int k=0;; K++)
{
If (a [k] <='9' & amp; & A [k] & gt;='0')//if the character for the digital
{
TMP [0]=a, [k]. TMP [1]='\ 0';
Printf (" TMP=% s \ n ", TMP);
Sscanf (TMP, "% d", & amp; N [j]);//character can be converted to an integer

Printf (" n [% d]=% d ", j, n [j]);
}
Else if (a [k]=='\ n')//meet end enter
{
break;
}
}

}

Thank you very much!
I have a post, please see the man X X

CodePudding user response:

refer to 6th floor QZJHJXJ response:
 # include & lt; Stdio. H> 
#include
#include
#include //useless
Void main ()
{
//{
Printf (" hw additional \ n ");
Int I, j=0, n [1000].

Char a [1000], TMP [2];
Gets (a);//input string, such as: 1-2
For (int k=0;; K++)
{
If (a [k] <='9' & amp; & A [k] & gt;='0')//if the character for the digital
{
TMP [0]=a, [k]. TMP [1]='\ 0';
Printf (" TMP=% s \ n ", TMP);
Sscanf (TMP, "% d", & amp; N [j]);//character can be converted to an integer

Printf (" n [% d]=% d ", j, n [j]);
}
Else if (a [k]=='\ n')//meet end enter
{
break;
}
}

}

To be honest, didn't quite understand,,, TMP definition is what to do? My original code in the TMP seems futile,,,

Also, what's the matter with your blue background of the code is a sticker?

Oh, the most important still is my another post, and fast by the crazy, look at the trouble
  • Related