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
How do i reinitialize a char array in one line if i want to use the same array variable every time.

char name[1024];

Aug 19 '08 #1
9 7285
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,

Aug 19 '08 #2
3 New Member
i'm not sure..
i will ask my lecturer tomorrow.
i hope i can help you..
Aug 19 '08 #3
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..
Aug 23 '08 #4
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..
memset(name, 0, 1024);
Aug 23 '08 #5
9,065 Recognized Expert Moderator Expert
You could assign new data to the array using strcpy or memcpy
Aug 23 '08 #6
30 New Member
Can memset be use for C++.

Aug 23 '08 #7
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
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
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,

Aug 23 '08 #10

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

Similar topics

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...
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); ----------
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
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;
by: Yang Lee | last post by:
hi is this correct char teststr="\0"; or is there another method to initialise; thanks lee
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
by: wenmang | last post by:
hi, I have following: struct array1 { int id; char *name; }; struct array2 {
by: thinktwice | last post by:
char a = { 0 } is it ok?
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.
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...
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...
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,...
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...
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...
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...
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...
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
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.