Sponsored Content
Top Forums Programming C system() how to send the output to an array?? Post 302388288 by pludi on Wednesday 20th of January 2010 02:17:36 AM
Old 01-20-2010
From the man page of strcat (emphasis added)
Quote:
The strcat() function appends the src string to the dest string, overwriting the null byte ('\0') at the end of dest, and then adds a terminating null byte. The strings may not overlap, and the dest string must have enough space for the result.[...]
If src contains n or more characters, strcat() writes n+1 characters to dest (n from src plus the terminating null byte). Therefore, the size of dest must be at least strlen(dest)+n+1.
So as soon as you read more that 512 bytes from the process (which, with netstat will happen almost guaranteed) you'll start trying to write into unreserved space. This space might already be claimed by another process, and so the system intervenes.

One approach might be to allocate a large enough part of memory at the beginning.
A better approach would be to allocate a bit of memory using malloc(), and expanding that if needed using realloc().
 

10 More Discussions You Might Find Interesting

1. Programming

can we send arguments to system() call

Hi friends my C code is int main() { system("cp <source> <destination>"); } my question is how to set variables for <source> and <destination> how can we pass it to system() call. can you suggest me thankyou kingskar (6 Replies)
Discussion started by: kingskar
6 Replies

2. UNIX for Advanced & Expert Users

To send a message to another system

How to send a message to another unix terminal along with the date specified (4 Replies)
Discussion started by: aajan
4 Replies

3. UNIX for Dummies Questions & Answers

send message to a remote system

I am analyzing snoop output and want to send "Hello world" to a remote system. I want to see if the message received is encrypted or not. can I use ping to send a text message? like ping "helloworld" <IP Addr> Please help. Thank you (5 Replies)
Discussion started by: rakeshou
5 Replies

4. Solaris

how to send the output

Hi, how to send the output of a command directly to a file. For eg: am issuing metastat -a. How to send the output of this command to a file as well as mail. (3 Replies)
Discussion started by: rogerben
3 Replies

5. Shell Programming and Scripting

awk - Pre-populating an array from system command output

So, here's a scenario that requires the same logic as what I'm working on: Suppose that you have a directory containing files named after users. For awk's purposes, the filename is a single field-- something parse-friendly, like john_smith. Now, let's say that I'd like to populate an array in... (2 Replies)
Discussion started by: treesloth
2 Replies

6. Shell Programming and Scripting

System Output in to an Array or variable

hey guys in only new to scripting as such, but i have a problem. i want to take the output of a search i do in the command line to then be in a variable but only a certain part of the output. this this what im doing: -bash-2.05b$ ldapsearch -x '(dn:=dc)' dc|grep dc= # base... (1 Reply)
Discussion started by: jmorey
1 Replies

7. Filesystems, Disks and Memory

iostat output vs TPC output (array layer)

Hi Guys, I've been having some arguments with my colleagues about one thing. Always my thought was that as as far as disk performance is concern by looking at the output of the iostat command (AIX) you would be able to identify if you have a hot disk and then by moving some files out that disk... (3 Replies)
Discussion started by: arizah
3 Replies

8. UNIX for Dummies Questions & Answers

[Solved] Reading Array And Send An Email

I am trying to find an example for reading an array instead of reading a file and send out an email in ksh. Can you please help is that possible? Algorithm #!/bin/ksh i=0 set -A ARR if then let i=$ ARR="A does n't match with B" fi if then let i=$ ARR="P does n't match with Q"... (11 Replies)
Discussion started by: Ariean
11 Replies

9. UNIX for Dummies Questions & Answers

Send files automatically to a remote system

Greetings, basically what I want to do is take the standard error from a cron file and store it on a file in a remote host (from Solaris to Linux). I want to create a cron file to do this everyday or put it on a script that will send it everyday to the other system (that doesnt matter). Any ideas... (2 Replies)
Discussion started by: picolin
2 Replies

10. Shell Programming and Scripting

I want query output to send on mail using table tag and output should be in table

#! /bin/ksh #] && . ./.profile 2>/dev/null if test -f '.profile'; then . ./.profile; fi; #. .profile LOG_DIR=/app/rpx/jobs/scripts/just/logs sendEmail() { pzCType="$1"; pzTitle="$2"; pzMsg="$3"; pzFrom="$4"; pzTo="$5"; pzFiles="$6"; pzReplyTo="$7" ( ... (21 Replies)
Discussion started by: ankit.mca.aaidu
21 Replies
STRCAT(3)						     Linux Programmer's Manual							 STRCAT(3)

NAME
strcat, strncat - concatenate two strings SYNOPSIS
#include <string.h> char *strcat(char *dest, const char *src); char *strncat(char *dest, const char *src, size_t n); DESCRIPTION
The strcat() function appends the src string to the dest string, overwriting the terminating null byte ('') at the end of dest, and then adds a terminating null byte. The strings may not overlap, and the dest string must have enough space for the result. If dest is not large enough, program behavior is unpredictable; buffer overruns are a favorite avenue for attacking secure programs. The strncat() function is similar, except that * it will use at most n bytes from src; and * src does not need to be null-terminated if it contains n or more bytes. As with strcat(), the resulting string in dest is always null-terminated. If src contains n or more bytes, strncat() writes n+1 bytes to dest (n from src plus the terminating null byte). Therefore, the size of dest must be at least strlen(dest)+n+1. A simple implementation of strncat() might be: char * strncat(char *dest, const char *src, size_t n) { size_t dest_len = strlen(dest); size_t i; for (i = 0 ; i < n && src[i] != '' ; i++) dest[dest_len + i] = src[i]; dest[dest_len + i] = ''; return dest; } RETURN VALUE
The strcat() and strncat() functions return a pointer to the resulting string dest. ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +--------------------+---------------+---------+ |Interface | Attribute | Value | +--------------------+---------------+---------+ |strcat(), strncat() | Thread safety | MT-Safe | +--------------------+---------------+---------+ CONFORMING TO
POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD. NOTES
Some systems (the BSDs, Solaris, and others) provide the following function: size_t strlcat(char *dest, const char *src, size_t size); This function appends the null-terminated string src to the string dest, copying at most size-strlen(dest)-1 from src, and adds a terminat- ing null byte to the result, unless size is less than strlen(dest). This function fixes the buffer overrun problem of strcat(), but the caller must still handle the possibility of data loss if size is too small. The function returns the length of the string strlcat() tried to create; if the return value is greater than or equal to size, data loss occurred. If data loss matters, the caller must either check the arguments before the call, or test the function return value. strlcat() is not present in glibc and is not standardized by POSIX, but is available on Linux via the libbsd library. EXAMPLE
Because strcat() and strncat() must find the null byte that terminates the string dest using a search that starts at the beginning of the string, the execution time of these functions scales according to the length of the string dest. This can be demonstrated by running the program below. (If the goal is to concatenate many strings to one target, then manually copying the bytes from each source string while maintaining a pointer to the end of the target string will provide better performance.) Program source #include <string.h> #include <time.h> #include <stdio.h> int main(int argc, char *argv[]) { #define LIM 4000000 int j; char p[LIM]; time_t base; base = time(NULL); p[0] = ''; for (j = 0; j < LIM; j++) { if ((j % 10000) == 0) printf("%d %ld ", j, (long) (time(NULL) - base)); strcat(p, "a"); } } SEE ALSO
bcopy(3), memccpy(3), memcpy(3), strcpy(3), string(3), strncpy(3), wcscat(3), wcsncat(3) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. GNU
2017-09-15 STRCAT(3)
All times are GMT -4. The time now is 06:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy