473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

C Programming Typecasting Linux

Hi I am trying to work on a program that needs typecasting.
If I compile and run the program I get a segmentation fault.

I have found that the following code is the problem:

char* command;
int controller = 02;
strcpy(command,"V");
strcat(command,(char*) controller);

The controller is passed from a calculation and is sent as an integer, but i have to write a string to the serial port.

Is there another way to convert an integer to a string?
Apr 4 '07 #1
3 1750
Banfa
9,065 Expert Mod 8TB
the reason you are getting a segmentation fault is that you do not point the pointer you create (command) and any allocated memory before copying to it.

For converting ints to strings use sprintf or itoa (functions from the standard library).
Apr 4 '07 #2
the reason you are getting a segmentation fault is that you do not point the pointer you create (command) and any allocated memory before copying to it.

For converting ints to strings use sprintf or itoa (functions from the standard library).

Thank you,

Do you know where the itoa in the Linux operating system? I have stdlib and stdio included, but it gave me an implicit definition error
Apr 5 '07 #3
Banfa
9,065 Expert Mod 8TB
Thank you,

Do you know where the itoa in the Linux operating system? I have stdlib and stdio included, but it gave me an implicit definition error
Oops just checked, itoa
is not actually part of the standard library so may not be implemented on your platform.

Grep the standard headers for it or just use sprintf.
Apr 5 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dont bother | last post by:
Here am I, On the border...if someone can help me, it would be nice: I have a string: feature_vector. It is of the form <index: value, index: value, index: value> I want to make this...
2
by: Arun Prasath | last post by:
Hi all, I have the following question regd pointer typecasting. Is the following type of pointer typecasting valid? #define ALLOC(type,num) ((type *)malloc(sizeof(type)*num)) /*begin...
12
by: G. | last post by:
Hi all, During my degree, BEng (Hons) Electronics and Communications Engineering, we did C programming every year, but I never kept it up, as I had no interest and didn't see the point. But now...
11
by: Vinod Patel | last post by:
I have a piece of code : - void *data; ...... /* data initialized */ ...... struct known_struct *var = (struct known_struct*) data; /*typecasting*/ How is this different from simple...
19
by: ceo | last post by:
hi, why do i get the following error? do i need to explicitly typecast the pointer returned by malloc to char *? thanks, ceo # cat malloc.cpp #include <stdio.h>
3
by: jdm | last post by:
In the sample code for the SortedList class, I see the use of a string typecasting macro consisting of a single letter "S". i.e.: Sortedlist->Add(S"Keyval one", S"Item one"); Now I have...
10
by: stylecomputers | last post by:
Hey guys, I am absolutely new to Linux programming, with no w######s programming experience except a small amount of C++ console apps. Reasonably new to Linux, BSD etc, got good sound networking...
12
by: bwaichu | last post by:
What is the best way to handle this warning: warning: cast from pointer to integer of different size I am casting in and out of a function that requires a pointer type. I am casting an...
5
by: Jon Rea | last post by:
I work with molecular simulations. In a normal infinate space simulation, a particle can occupy any cartesian position in space. If i want the distance between two particles in a system I can...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.