473,796 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

strncpy to a char member of struct

Hi,

I have this struct initialized globally:
struct riddle {
char *text;
....
}

below, the function I call in main with the riddle struct as arg. is
defined:
void prepareRiddle(s truct riddle *riddle)
{
// here I get a string (char *tmp) with a known size (int length)
incl. terminator.
riddle->text = (char*)malloc(l ength * sizeof(char)); // figured
sizeof(char) could be != 1 on some platforms
....
}

still, sizeof(riddle.t ext) called in main() doesn't give me the numbers
I had hoped for.

Am I accessing the text member in my riddle struct inappropriately ?

Thanks.

Apr 21 '06
12 2396
A big thank you to all of you.

Especially you guys who gave hints and guidelines on posting on Usenet
(and newsgroups in general), and of course to Flash Gordon for the
technical insight.

Regards,
Anders

Apr 24 '06 #11
"Default User" <de***********@ yahoo.com> wrote:
Richard Bos wrote:
"Default User" <de***********@ yahoo.com> wrote:

Btw, I used the Gmail Groups online poster 3. It's Google Groups.


No, it's fscking not! It's Usenet; these are newsgroups.


Jeez Richard. I've only been posting here for like 12 years, before
Google Groups even existed. You managed to completely miss the entire
point. I've winnowed it down for you.


My apologies. It must be Google Groups users getting on my tits, but
that doesn't excuse my sloppy reading.

Richard
Apr 25 '06 #12
Richard Bos wrote:
"Default User" <de***********@ yahoo.com> wrote:
Richard Bos wrote:
"Default User" <de***********@ yahoo.com> wrote:

> Btw, I used the Gmail Groups online poster

> 3. It's Google Groups.

No, it's fscking not! It's Usenet; these are newsgroups.


Jeez Richard. I've only been posting here for like 12 years, before
Google Groups even existed. You managed to completely miss the
entire point. I've winnowed it down for you.


My apologies. It must be Google Groups users getting on my tits, but
that doesn't excuse my sloppy reading.

I understand. At least this group tries to deal with the Google
situation, and definitely for the better. Over on comp.lang.c++, the
no-quoting is rampant, and they're just now starting to pipe up about
it.


Brian

Apr 25 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
17656
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have two questions: 1. Is it generally safe to "overlay" the structure on the buffer, e.g.: unsigned char buffer;
7
5293
by: Angus Comber | last post by:
Hello Here is my code so far. Is this correct/incorrect/along the right lines/other? #include <stdio.h> #include <string.h> #include <search.h> struct mystruct {
4
4483
by: Barry | last post by:
Hi all! I support a rather large production EDI application with a number of C programs, and I ran across a very interesting problem. I have some code that used to work just fine for years, and now all of a sudden it doesn't work any more. The input to the program did not change at all (even ran it through a binary browser to make certain there were no hidden chars or something strange) and the program has not been recompiled in years....
9
2038
by: fybar | last post by:
Hi, I am in the progress of writing a program that will read in the contents of a directory and then do some stuff to some of the files. So far I am getting the contents of the directory but I get a strange result from one file. Here is my program, feel free to critique: #include <sys/types.h> #include <dirent.h> #include <stdio.h>
53
4295
by: SK | last post by:
Hi I appreciate all of the feedback I have recieved. I am enjoying working on my program and I hope that it can be appreciated. I have my program compiling now and I am continuing to work out the bugs. I have two problems that I cannot seem to resolve: 1. I want to have someone enter in as many employees as they want to..and for each employee entered I would like to save the data from that entry to print out at the end of the...
31
7760
by: aarklon | last post by:
Hi all, this is a question which i saw in a book typedef struct mall_li_header_ { int refcnt; uchar pool; uchar flag; ushort magic_no; char data;
4
9539
by: chikito.chikito | last post by:
1. Can someone tell me the difference between these two functions: void strcpy(char *s1, const char *s2) { while(*s1++ = *s2++) ; } //function prototype of strcpy follows char *strcpy(char *s1, const char *s2) // library function
4
5772
by: lurch132002 | last post by:
i am trying to create an array of structs to hold some information but whenever i get to the second element and try to strncpy it i get a segmenation fault. ive searched around for similar problems but i cant seem to figure out what im doing wrong. any help would be appreciated. #include <stdio.h> #include <stdlib.h> #include <string.h>
5
2288
osfreak
by: osfreak | last post by:
#include<iostream> using namespace std; typedef struct mystruct { unsigned char uDirFlag; unsigned int uFileSize; char uFilename;
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10459
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10018
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9055
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5446
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.