CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

problem on sending string by using fputs

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
baris_akinci



Joined: 10 Mar 2016
Posts: 17
Location: Ankara

View user's profile Send private message

problem on sending string by using fputs
PostPosted: Tue Sep 20, 2016 1:54 pm     Reply with quote

Hello, I need help to understand what is the main reason CCS C put extra value when I try to send string by using fputs via rs232 connection. the code belock is below
Code:
       
       
         char gonder[3];
         char gecici;
         char gonder[4];
               
         if (time <= 13) {    gecici='0';  } 
         else                 {    gecici='1';  }
         gonder[0]=gecici;
         gonder[1]=sifre[2];     // entered pasword part -> 1
         gonder[2]=sifre[3];     // entered pasword part -> 4
         
         fputs(gonder);

       

I just want to see 114 instead of 114r. where this "r" comes from?? see the picture below. thanks in advance.
[IMG]
https://resmim.net/f/dhJlMv.png
[/IMG]
Ttelmah



Joined: 11 Mar 2010
Posts: 19447

View user's profile Send private message

PostPosted: Tue Sep 20, 2016 2:13 pm     Reply with quote

You are lucky to only get an extra 'r'...

This is not anything special about CCS, but standard 'C'.
In 'C', a 'string' is a "null terminated array of characters". You are not adding the null terminator. fputs, will keep printing, until it sees such a terminator, so what you get 'extra' will depend on what happens to be in memory.....

You need to add:

gonder[3]='\0';

to terminate the array, before you try to print.
baris_akinci



Joined: 10 Mar 2016
Posts: 17
Location: Ankara

View user's profile Send private message

problem on sending string by using fputs
PostPosted: Wed Sep 21, 2016 12:45 pm     Reply with quote

thank you so much Ttelmah. I have tried your advice and got the result well.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group