473,466 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

remove bogus char

2 New Member
Hi all,

I am trying a strncpy (tempstr,srcstrng,sizeof(tempstr));

where in char tempstr[200];
char srcstng[100];

in this case in the destination array many free mem is present & when i retrive tempstr i get bogus char appended with the string .

i have tried using strncpy (tempstr,srcstrng,strlen(srcstrng));

but still the problem continues .Can someone help me with this please ?

thanks ,
Viba
Dec 16 '07 #1
4 1642
oler1s
671 Recognized Expert Contributor
and srcstring is nul terminated as a proper C string? Can you, before copying the string over, confirm that the last character is the NUL character?
Dec 16 '07 #2
weaknessforcats
9,208 Recognized Expert Moderator Expert
You have to be careful wirth strncpy(). If it encounters a null terminator before the charcter copy limit is reached, it copies the null terminator and quits. Other wise it just quits at the character copy limit leaving the destination with no null terminator. Your destination, in this case, is a string of characters of indefinite length. It will include everything in memory until a binary zero is encountered. Hence the bogus characters.
Dec 16 '07 #3
viba
2 New Member
and srcstring is nul terminated as a proper C string? Can you, before copying the string over, confirm that the last character is the NUL character?
yes .srcstring is a proper null terminated string ..
Dec 17 '07 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
Better post your code. I would like to see how you are calling this function.
Dec 17 '07 #5

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

Similar topics

2
by: Luke | last post by:
Hi, I'm getting an OverflowError which doesn't make sense to me. Is this a python bug? Traceback (most recent call last): File "/home/demoau/lib/py/omniORB/__init__.py", line 717, in...
12
by: Oberon | last post by:
I have a large HTML document. It has hundreds of <span>s which have no attributes so these <span>s are redundant. How can I remove these tags automatically? The document also has <span>s with...
0
by: Trophy Thief | last post by:
I'm getting an odd error when I try to run a select statement in my stored procedure. I need to select records where one field = the first host variable, and the second host variable is between the...
11
by: deko | last post by:
I need to loop through a string and remove all characters except numbers or letters. I am getting an ArgumentOutOfRangeException: "Index was out of range. Must be non-negative and less than the...
5
by: Tiger | last post by:
Hi, I try to send a packet with raw socket but I have an error with ethereal sniffer on windows xp. I can't find any solution on the net. :( Could anybody help with that problem? my code :...
34
by: Registered User | last post by:
Hi experts, I'm trying to write a program that replaces two or more consecutive blanks in a string by a single blank. Here's what I did: #include <stdio.h> #include <string.h> #define MAX 80
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
26
by: Brad | last post by:
I'm writing a function to remove certain characters from strings. For example, I often get strings with commas... they look like this: "12,384" I'd like to take that string, remove the comma...
1
by: nyc680 | last post by:
for this c program, i'd like to remove the substring "cc" and character "=" from input string "aaccbbccdd" the code below can only remove "cc" once, can somebody help me figure out how to remove...
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
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
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...
1
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...
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.