Sponsored Content
Top Forums Programming STL algorithm merge() function to concatenate char arrays Post 302635865 by Corona688 on Sunday 6th of May 2012 01:00:29 PM
Old 05-06-2012
str[0] is the first character in the string, str[strlen(str)] is one beyond the last character of the string, etc, etc. I have no idea how you expected to get HelloWorld.

You should not be declaring arrays with dynamic sizes. Never use things like strlen() in an array size.

STL has absolutely no purpose here since you're using C strings.

Code:
#include <string.h>
#include <stdio.h>

int main(void)
{
    char str[] = "Hello";
    char srch[] = "World";
    char output[512];

    output[0]='\0';
    strcat(output, str);
    strcat(output, srch);
    printf("output is %s\n", output);
}

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell: creating different arrays based on function argument

hi, I was wondering if there was a good way to create an array within a function, where the name is based on a passed argument? I tried this: _____________________________ func(){ #take in 1st arg as the arrayname arrayName=$1 let i=0 while read line do arrayName=${line} let i+=1... (5 Replies)
Discussion started by: nix21
5 Replies

2. Programming

C programming + problem with char arrays

Im trying to write some code atm which gets the complete pathname of a folder and strips off references to the parent folders. The end result should be just the name of the folder. Currently Im able to extract the folder name, however Im getting junk added onto the name as well which is making... (7 Replies)
Discussion started by: JamesGoh
7 Replies

3. Shell Programming and Scripting

Recursive function and arrays

I have the following function in a bash script that fails to return the sorted array. I think the problem lies in the recursion not correctly passing the arrays, but I can't tell what I'm doing wrong. Anyone see the problem? function quicksort () { local array=( `echo "$1"` ) local... (7 Replies)
Discussion started by: tkg
7 Replies

4. Programming

Char arrays

This is in C++. Is there a way to take characters out of input data? For example, hello 0 1 2 3 4 5 is within my double dimensional array: char arr; How would I output only the characters h,e,l,l,o? (0 Replies)
Discussion started by: puttster
0 Replies

5. Programming

unable to send a char parameter from main to a function

why does this not work? #include <stdio.h> #include <stdlib.h> char getFileMode(char charChanger) { char filetype; /*var to hold the value to be returned*/ filetype = charSetter; /*set filetype to "l" if it is a symlink*/ return filetype; } int main(void){ char... (8 Replies)
Discussion started by: bluetxxth
8 Replies

6. Programming

Small query regarding function "char * strerror(int errnum)"

As this function returns the address of the string corressponding to the errno value provided to it. Can someone please let me know where, in the memory, it could be (on freeBSD). The MAN page tells under the BUG section that "For unknown error numbers, the strerror() function will return its... (5 Replies)
Discussion started by: Praveen_218
5 Replies

7. Shell Programming and Scripting

Java - Arrays.binarySearch function equivalent in awk

Hi all Does anyone know Java-Arrays.binarySearch function equivalent in awk I tried like this but it's not correct one,it just returns array index if and only when searched value available in array, for some reason if searched value not found then I want to return upper nearest neighbour index.... (1 Reply)
Discussion started by: Akshay Hegde
1 Replies

8. Shell Programming and Scripting

Awk, function of underscore char.

Hello Friends, I would appreciate so much if you could explain how the underscores works at the following code? Sorry if it sounds a bit novice question. awk -F',' 'NR==FNR{_=1;next}!_{print}' exclude infile KR, Eagle (6 Replies)
Discussion started by: EAGL€
6 Replies

9. Shell Programming and Scripting

Merge two input files and concatenate the rest

Hi Guys, I need a help to creating a bash script to merging two files that containing not in order pattern into single file also within that single file I need to concatenate and manipulate the string from two files. Appreciate for any kind help given. Thanks. Here are the input files:... (3 Replies)
Discussion started by: jabriel
3 Replies

10. Programming

Segmentation fault when I pass a char pointer to a function in C.

I am passing a char* to the function "reverse" and when I execute it with gdb I get: Program received signal SIGSEGV, Segmentation fault. 0x000000000040083b in reverse (s=0x400b2b "hello") at pointersExample.c:72 72 *q = *p; Attached is the source code. I do not understand why... (9 Replies)
Discussion started by: jose_spain
9 Replies
addstr(3cur)															      addstr(3cur)

Name
       addstr, waddstr, mvaddstr, mvwaddstr - add string to window

Syntax
       #include <cursesX.h>

       int addstr(str)
       char *str;

       int waddstr(win, str)
       WINDOW *win;
       char *str;

       int mvaddstr(y, x, str)
       int y, x;
       char *str;

       int mvwaddstr(win, y, x, str)
       WINDOW *win;
       int y, x;
       char *str;

Description
       The routine writes all the characters of the null-terminated character string on the default window at the current (y, x) coordinates.

       The routine writes all the characters of the null terminated character string on the specified window at the current (y, x) coordinates.

       The routine writes all the characters of the null terminated character string on the default window at the specified (y, x) coordinates.

       The routine writes all the characters of the null terminated character string on the specified window at the specified (y, x) coordinates.

       The  following  information  applies to all the routines.  All the routines return if writing the string causes illegal scrolling.  In this
       case the routine will write as much as possible of the string on the window.

       These routines are functionally equivalent to calling or once for each character in the string.

       The routines and are macros.

Return Values
       The and functions return OK on success and ERR on error.

See Also
       addch(3cur), waddch(3cur)

																      addstr(3cur)
All times are GMT -4. The time now is 12:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy