473,883 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Initialize char array in one line

30 New Member
Hi
How do i reinitialize a char array in one line if i want to use the same array variable every time.
Ex-

char name[1024];

-Ashok
Aug 19 '08 #1
9 7285
JosAH
11,448 Recognized Expert MVP
You can't 're-initialize' anything, you can just assign another value to the members
of the array. Why do you want to do that on one line? Homework?

kind regards,

Jos
Aug 19 '08 #2
huzen88
3 New Member
i'm not sure..
i will ask my lecturer tomorrow.
i hope i can help you..
Aug 19 '08 #3
ashokd001
30 New Member
This is not just a home wark.
If i want to use the same array , then i have to re-initialize it so it will be very easy if i can do it in one line.

any suggestion..
-ASK
Aug 23 '08 #4
leejwen
50 New Member
This is not just a home wark.
If i want to use the same array , then i have to re-initialize it so it will be very easy if i can do it in one line.

any suggestion..
-ASK
memset(name, 0, 1024);
Aug 23 '08 #5
Banfa
9,065 Recognized Expert Moderator Expert
You could assign new data to the array using strcpy or memcpy
Aug 23 '08 #6
ashokd001
30 New Member
Can memset be use for C++.

Regards,
Ask
Aug 23 '08 #7
Banfa
9,065 Recognized Expert Moderator Expert
Yes, of course if you are using C++ you should consider using a vector instead of an array with all its associated member.
Aug 23 '08 #8
boxfish
469 Recognized Expert Contributor
I've never seen memset before, so it seems wierd to me. Isn't strcpy a better choice somehow? It was designed for this, right?
Aug 23 '08 #9
JosAH
11,448 Recognized Expert MVP
I've never seen memset before, so it seems wierd to me. Isn't strcpy a better choice somehow? It was designed for this, right?
The strcpy() function needs a \0 terminated sequence of chars; memset() simply
sets every element to the same value. Also memcpy() can be of use; it depends.

kind regards,

Jos
Aug 23 '08 #10

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

Similar topics

6
2592
by: steveneng | last post by:
C++ Primer Plus Programming Exercises 4th Ed - Prate Help I'm trying to refresh myself and I'm stuck on this problem (not homework/school related but for personal advancement). 6: Do programming exercise 3, but, instead of declaring an array of three CandyBar structures, use new to allocate the array dynamically. That's the question in case you guys don't ahve the book. I have Exercises 3 done and I can properly use structures. But...
74
43341
by: Peter | last post by:
Hi, So many times, I have seen compile warning: "you used a char* without initilize it", probably on the code like this: ------------ char* ptr; func(..., ptr); ----------
9
27125
by: Niels Dekker - no reply address | last post by:
Are all the following initializations semantically equivalent? wchar_t a = {L'\0'}; wchar_t b = {'\0'}; wchar_t c = {0}; wchar_t d = {}; If so, why don't we all use an empty initializer list, {}, when zero-initializing a C-style string? I was wondering, because the book C++ Coding Standards (Sutter & Alexandrescu) says at item 19, "Always
6
54984
by: Ramprasad A Padmanabhan | last post by:
I have a simple structure defined like this struct userid { char uid; int insize; int outsize; }; typedef struct userid user;
10
43480
by: Yang Lee | last post by:
hi is this correct char teststr="\0"; or is there another method to initialise; thanks lee
1
4728
by: DC | last post by:
Hi, I am programming a windows service and all went well until I needed to use a simple array of chars which I initialize like this: char test = new char {'\x002F', '\x005E'}; Immediatly upon starting the service with this line in code (long before this line is even being used) I get a System.TypeLoadException which I cannot debug since it seems to happen somwhere deep in the
10
3046
by: wenmang | last post by:
hi, I have following: struct array1 { int id; char *name; }; struct array2 {
15
26446
by: thinktwice | last post by:
char a = { 0 } is it ok?
1
4378
by: BrandonG | last post by:
I am working on a JNI project, the env->NewStringUTF function will only accept a const char as a parameter. The trouble I am having is that within the native method I need to modify the string that is passed in and then return it. If i can initialize and put the data I need into a non-constant char then is there a way to create a const char that contians the data in the non-const one then pass the const array to the JNI function.
0
9938
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
10742
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10847
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10414
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
9572
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...
1
7971
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5797
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...
1
4611
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
3
3232
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.