CCS News

New Feature: scanf() for Inputting Strings and Parsing

Wednesday 02 October, 2013

The CCS C Compiler's latest version supports a new function, scanf(). The scanf() function allows inputting a formatted string over the RS232 and parsing the received string into specified variables. For example the following will input the string "Name: CCS Time: 18430 Count: 58437" and store the received name in an array, the received time in an unsigned int32 variable and the received count in an unsigned int16 variable:

#include <18F45K22.h>
#fuses NOWDT
#use delay(internal=32MHz)
#use rs232(UART1,baud=9600,receive_buffer=100)

void main()
{
char name[10];
unsigned int32 time;
unsigned int16 count;

enable_interrupts(GLOBAL);

while(TRUE)
{
scanf(" Name: %s Time: %lu Count: %lu",name, &time, &count);

if(count > 0)
printf("rnCount %lu - Name: %s, Time: %lu",count, name, time);
}
}

Learn more about other compiler features and functions by visiting: http://www.ccsinfo.com/picc
Check out all the new devices supported and drivers in the latest compiler.

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit http://www.ccsinfo.com.

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.