Thursday, November 18th, 2010

String Manipulation in MikroC

String Manipulation in MikroC using microcontroller PIC 16f877 or PIC18f452,PIC18F4550:
Problem statement:
Write a program to illustrate how the two strings “The best Microcontroller” and “in PIC Micro Family” can be joined into a new string using String library functions.
Solution:-
The required program listing is shown below (program JOIN.C). The mikroC String library function strcat is used to join the two strings pointed to by p1 and p2 into a new string stored in a character array called New_String. “in PIC Micro Family” can be joined into a new string using String library functions.

JOINING TWO STRINGS
===================
This program shows how two strings can be joined to obtain a new string. mikroC library function strcat is used to join the two strings pointed to by p1 and p2 into a new string stored in character array New_String.
Programmer:

void main()
{
const char *p1 = “The best Microcontroller” ; // First string
const char *p2 = “in PIC Micro Family”; // Second string
char New_String[80];
strcat(strcat(New_String, p1), p2); // join the two strings
}

Function Description
strcat, strncat Append two strings
strchr, strpbrk Locate the first occurrence of a character in a string
strcmp, strncmp Compare two strings
strcpy, strncpy Copy one string into another one
strlen Return the length of a string

Commonly used Miscellaneous library functions in MIKROC programming language are as under:

Function Description
ByteToStr Convert a byte into string
ShortToStr Convert a short into string
WordToStr Convert an unsigned word into string
IntToStr Convert an integer into string
LongToStr Convert a long into string
FloatToStr Convert a float into string
Bcd2Dec Convert a BCD number into decimal
Dec2Bcd Convert a decimal number into BCD

Problem :
Write a function to convert the string pointed to by p into lowercase or uppercase,depending on the value of a mode parameter passed to the function. If the mode parameter is nonzero, then convert to lowercase, otherwise convert it to uppercase. The function should return a pointer to the converted string.
Problem :
Write a program to define a complex number structure, then write functions to add and subtract two complex numbers. Show how you can use these functions in a main program.

The mikroC language library functions have also been described briefly, along with examples of how to use several of these functions in main programs. Library functions simplify programmers’ tasks by providing ready and tested routines that can be called and used in their programs.

PIC 16F877, 18F452 and 18F4550,PIC16F877, PIC18F452,PIC18F4550,16f876,16f84,microcontroller projects,lm35,lm34,lm335,temperature sensor,MikroC Projects

2 Responses

12/12/2011

Thank you for this. I have tried the code above but an error came out, “Illegal pointer conversion”, in these line: strcat(strcat(New_String, p1), p2); // join the two strings


12/12/2011

By the way I am using MikroC PRO v4.60.
Thank you!