473,385 Members | 1,834 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,385 software developers and data experts.

Concatenating a single char from a structure to a string

1
I appreciate any help; I'm currently getting a problem with trying to concatenate a single char from a structure to an existing string. Basically, the problem is here:

strcat( res, morse_c[j].letter )

morse_c[j].letter should return an alphabet 'a' or 'b', etc...
I'm trying to concatenate that to a char *res and it returns the error:

'strcat' : cannot convert parameter 2 from 'char' to 'const char *'

I"ve tried casting it --> (const char*) morse_c[j].letter AND forcing the alphabets to const char type by using double quotes "a", "b", etc...

None worked. I've also tried setting res[i] = morse_c[j].letter and it doesn't work. When I return res, it only returns the first value res[0] and not the whole res string

Thank you!

PS: I'm thinking of changing my structure of letter to const char* but that will be a mess.

Code snipets:

char *res = (char *)calloc(200, sizeof(char));

Structure data:
typedef struct {
char letter;
char sequence[100];
} morse_t;

morse_t* codeGen(){
morse_t *res = (morse_t*) calloc(TABLE_SZ, sizeof(morse_t));
res[0] = make_morse( 'a', ".-" );
res[1] = make_morse( 'b', "-...");
res[2] = make_morse( 'c', "-.-.");
res[3] = make_morse( 'd', "-..");
... until the table is populated
Jun 22 '07 #1
2 2131
try overloading the += operator and just resize the char * res and add the letter on the end, and don't forget to account for the null
Jun 22 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
strcat appends one string to another string. A char is not a string.

Create a string with your char and a \0.

If you are using C++, then do not use strcat. Use string:

Expand|Select|Wrap|Line Numbers
  1. string str;
  2. str += 'A';
  3.  
Jun 23 '07 #3

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

Similar topics

4
by: Venkat | last post by:
Hi All, I need to copy strings from a single dimensional array to a double dimensional array. Here is my program. #include <stdio.h> #include <stdlib.h>
7
by: War Eagle | last post by:
I have two byte arrays and a char (the letter S) I was to concatenate to one byte array. Here is what code I have. I basically want to send this in a one buffer (byte array?) through a socket. ...
2
by: vikas | last post by:
I have following structure in c++. typedef struct MMF_result_struct { int action; char text; int cols,rows; int month,day,year; } MMF_result; Now this structure is shared between C++ and C#...
21
by: c | last post by:
Hi everybody. I'm working on converting a program wriiten on perl to C, and facing a problem with concatenate strings. Now here is a small program that descripe the problem, if you help me to...
10
by: Neil | last post by:
Using the MS Rich Textbox Control 6.0 in Access 2000, I need to concatenate several RTB controls into a single RTF file. Sometimes two strings will be side-by-side; other times they need to be...
3
by: Big Brother | last post by:
I've been thinking about the seemingly simple task of writing a va_arg-type function to concatenate arbitarily many strings. My first thoughts violated the following principles: 1) never...
4
by: ...vagrahb | last post by:
Hi, I have the following structure struct Format { char x; unsigned char a; unsigned char b; unsigned char c; char y;
20
by: =?Utf-8?B?ZW1pdG9qbGV5ZXM=?= | last post by:
Hi everyone: i read from the documentation of a dll that there is a struct that uses char for storing an IP address. How can it be? and how come i can get to representate the same value in a...
17
by: eBob.com | last post by:
I know it wouldn't be hard to write, but I have been unable to find a method which will take elements of a character array and concatenate them into a string. I've looked at both String members...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.