473,406 Members | 2,371 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,406 software developers and data experts.

strcat() causing segment fault?

Hey i've been trying to get this to work for a while now but nothing i do fixe it.
causes a seg fault at strcat.
Here is the code snippet:

Expand|Select|Wrap|Line Numbers
  1. int i=1;
  2. char *opt = " ";
  3. char s = '-';
  4.  
  5. if((argc>1) && s==arg[i][0]){
  6.     strcat(opt, arg[i]);
  7. }
...

argc/arg[] recieved in command line.

Any advice is appreciated!
Feb 16 '07 #1
1 1679
horace1
1,510 Expert 1GB
in the following statement " " is a constant
Expand|Select|Wrap|Line Numbers
  1. char *opt = " ";
  2.  
so you cannot use it as a destination in
Expand|Select|Wrap|Line Numbers
  1.     strcat(opt, arg[i]);
try
Expand|Select|Wrap|Line Numbers
  1. char opt[10] = " ";
making sure there is sufficent room in the array to receive the characters
Feb 16 '07 #2

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

Similar topics

2
by: linq936 | last post by:
Hi, I am using gcc3.2.3 as the compiler for my c++ code on Red Hat Linux Enterprise 3. I find that even an exception is caught, "Segment Fault" is still thrown out and program crashes. Here is...
5
by: Ian Stanley | last post by:
Hi, Having not done any C programming for a while I am trying to get back into it by converting an old java assignment into C. The problem is I am getting a segmentation fault at runtime which I...
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
15
by: Stanley S | last post by:
Hi, I'm puzzled. Why does the following cause a seg fault? Notwithstanding that I've already malloc() a certain space for "Hello". I do understand that using a fixed length array will work...
87
by: Robert Seacord | last post by:
The SEI has published CMU/SEI-2006-TR-006 "Specifications for Managed Strings" and released a "proof-of-concept" implementation of the managed string library. The specification, source code for...
9
by: Neal Barney | last post by:
I have a C program which runs on a device using a Zilog Z180 microprocessor. While it can address 1MB of RAM, it can only address 64KB at any given time. And of that only 16KB can be used for...
1
by: nass | last post by:
hello everyone.. i am not sure what is wrong - never liked strings anyway! my problem is that i am trying to save a QCstring in a shared memory segment and i get a segmentation fault.. here is...
1
by: pascal | last post by:
hi friends i am new to C on Linux env. My prob is why do we not get a segment fault when we try to find the value at 0 memory location where as a segment fault is shown if attempt is made to...
5
by: rtillmore | last post by:
Hi, I have run into a small snag with a program I am writing. I am generating a string using openssl DES_ecb_encrypt. The string is properly generated and contains the correct value. The...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.