View unanswered posts | View active topics It is currently Fri Oct 30, 2020 4:24 am

Reply to topic  [ 3 posts ] 
converting int to string 
Author Message

Joined: Mon Aug 18, 2014 5:19 pm
Posts: 1
Post converting int to string
i am trying to code a program that will allow me to see a number on the nxt display screen and be able to change that number by pressing the nxt buttons and my problem is that when i go to display the number i use the line: nxtDisplayCenteredTextLine(6, answer); and answer is a int. i thought that it would just display the int that i have answer as, but it gives me this error:**Error**:Procedure call Parameters don't match declaration for 'nxtDisplayCenteredTextLine(const long nLineNumber, const unsigned string & sFormatString, ...)'.

here is the rest of the code for that function:

#pragma config(Sensor, S3,     touch,          sensorTouch)
#pragma config(Motor,  motorA,          left,          tmotorNXT, PIDControl, encoder)
#pragma config(MotorPidSetting,  motorB,  255, 255, 65535, 255, 255,   65535, 65535, 65535)
#pragma config(MotorPidSetting,  motorC,  255, 255, 65535, 255, 255,   65535, 65535, 65535)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#define nxtorange 3
#define nxtleft 2
#define nxtright 1
#define nxtgrey 0

int Question1()
   int answer
   nxtDisplayCenteredTextLine(1, "left = add"); // Displays instructions
   nxtDisplayCenteredTextLine(2, "right = subtract"); // Displays instructions
   nxtDisplayCenteredTextLine(3, "press grey when done"); // Displays instructions
   nxtDisplayCenteredTextLine(6, answer)

   while(sensorvalue[nxtgrey] = -1)
      if(nNxtButtonpressed == nxtright)// checks if the right btn is pushed
         answer = answer + 1
         nxtDisplayCenteredTextLine(6, answer)

      if(nNxtButtonPressed == 2)// checks if the left btn is pushed
         answer = answer - 1
         nxtDisplayCenteredTextLine(6, answer)


   return answer;

Mon Aug 18, 2014 5:30 pm

Joined: Wed May 07, 2014 7:51 pm
Posts: 6
Post Re: converting int to string
Use the sprintf routine.

Declare a buffer string variable:
char buf[5];

To display convert the integer to a string:
sprintf(buf, "%d", answer);
nxtDisplayCenteredTextLine(6, buf);

Hope that helps.

Mon Aug 18, 2014 10:33 pm
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: converting int to string
nxtDisplayTextLine(6, "%d", answer) should also work.

= Xander

| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]

Mon Aug 18, 2014 11:33 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.