Suka
Anonymous
Where I Can Learn Flow Charts
Anonymous
Please Can Anyone Help Me
Ludovic 'Archivist'
Anonymous
I'm new here lads
Anonymous
I have a question that covers almost all topics of C . Any one interested to solve the question ?
Mac
Abdulaziz
can i save global objects to qsettings?
or is it good idea to hold instances in one class
+
I'm working on a project that I need to first read data from a file, then make some change to it, and then save it to another file (all in binary mode).
For reading, my first try was to open the file with ifstream and read directly from the file with read(), but because I need to read small bytes from the file back to back, I think it's not a good idea to keep reading data directly from the file itself. I mean, currently I'm doing it this way for reading the file into a structure and normal variables:
namespace DBinary {
#pragma pack(push, 1)
struct Structure
{
int32_t iData1;
int16_t iData2;
int16_t iData3;
int16_t iData4a;
int16_t iData4b;
int32_t iData4c;
};
#pragma pack(pop)
}
int main()
{
std::ifstream input(path, std::ios::binary);
//for reading structure
DBinary::Structure tstruc{};
file.read((char*)&tstruc, sizeof(DBinary::Structure));
//read single value
uint16_t anint = 0;
core_file.read((char*)&anint, sizeof(anint));
}
It's OK, but I think I can do it better, because the file isn't that big. Maybe I can read it fully into memory and then work on it? But I'm not sure what is the best way to do that, and how to do that, because I don't have much experience in C++ and I'm new to it.
I also want to be able to freely edit and change the data that I read from files, so its important for me to also support that.
Anonymous
hb
hb
https://en.cppreference.com/w/cpp/language/aggregate_initialization
Anonymous
I'm working on a project that I need to first read data from a file, then make some change to it, and then save it to another file (all in binary mode).
For reading, my first try was to open the file with ifstream and read directly from the file with read(), but because I need to read small bytes from the file back to back, I think it's not a good idea to keep reading data directly from the file itself. I mean, currently I'm doing it this way for reading the file into a structure and normal variables:
namespace DBinary {
#pragma pack(push, 1)
struct Structure
{
int32_t iData1;
int16_t iData2;
int16_t iData3;
int16_t iData4a;
int16_t iData4b;
int32_t iData4c;
};
#pragma pack(pop)
}
int main()
{
std::ifstream input(path, std::ios::binary);
//for reading structure
DBinary::Structure tstruc{};
file.read((char*)&tstruc, sizeof(DBinary::Structure));
//read single value
uint16_t anint = 0;
core_file.read((char*)&anint, sizeof(anint));
}
It's OK, but I think I can do it better, because the file isn't that big. Maybe I can read it fully into memory and then work on it? But I'm not sure what is the best way to do that, and how to do that, because I don't have much experience in C++ and I'm new to it.
I also want to be able to freely edit and change the data that I read from files, so its important for me to also support that.
the std::ifstream object has its own buffer. you don't need to worry about reading small amounts of data.
the rdbuf() member returns a pointer to the underlying buffer, you can change the buffer size through that if you want.
B121065_Swoyam Siddharth Nayak
is there any better optimised way for writing the function to add a specific element at a specific position in a linked list
class node{
public:
int data; //Date in the node
node* next; //(node* denotes a pointer pointing to a node data type) Address of the next node
node(int val){
data = val;
next = NULL;
}
};
void insertatposition(node* head, int pos, int val){
node* p=new node(val);
node* temp1=head;
node* temp2=head;
for(int i=1;i<pos;i++){
temp1=temp1->next;
}
for(int i=2;i<pos;i++){
temp2=temp2->next;
}
p->next=temp1;
temp2->next=p;
}
Pradevel (Pratyush)
😂
Anonymous
struct Node {
int value;
struct Node * next;
};
class LinkedList {
public:
LinkedList() {
head = nullprt;
tail = nullptr;
}
private:
Node *head;
Node *tail;
};
Mack
Thank you rose
+
+
but one other thing
+
what I actually after is what is the best way to create a buffer to store edited data for later to save to disk
バレンタインがいない柴(食用不可)
Good afternoon
バレンタインがいない柴(食用不可)
バレンタインがいない柴(食用不可)
You can have the second pointer calculated only when the first pointer arrives at the location just before the insertion point. You don’t need to traverse that second one
バレンタインがいない柴(食用不可)
It should then essentially cut down your running time by a half
Anonymous
Hi, when I pass an int array with size of 10 elements to a function, and then show the sizeof this array the program print 8 byte but when I show it in main function without pass it print 40 byte why is this the case and how to handle it
klimi
klimi
on 64bit system it is 8 * 8 bytes hence, that's why you get a 8 in the function
klimi
in the main function the compiler is smart enough to say you the size which you initialized
klimi
int size is standardly 4 bytes, so 10*4 is 40
Anonymous
Ok.. I get it.
What I want to do is make for loop inside that function I try to use sizeof to know how many elements I have, so maybe I should to pass the size with the array to the function
Anonymous
Hi, i am new in c program language can i get someone to teach me
Anonymous
I have dev c++ compiler
klimi
Anonymous
Anonymous
バレンタインがいない柴(食用不可)
https://www.coursera.org/courses?query=c%2B%2B
バレンタインがいない柴(食用不可)
Anonymous
Anonymous
+
GHAMDAN_NSHWAN
🆘
GHAMDAN_NSHWAN
Please......♥️
How do I delete recurring elements inside the stack
バレンタインがいない柴(食用不可)
+
let me ask straight, how can I create a buffer for save some data that I don't know exact size of them
I mean imagine I have some strings, and I want to add each of them to a char buffer and after that add the created char buffer to another.
how can I actually do that?
I will be grateful if someone answer this question
Big Boss
+
maybe you can try memory mapped files, for Windows
how can this help me?
there is no problem in reading and writing file
I just want a good solution to be able to freely edit (and store the edited data to a buffer) and at the end write edited data to disk
Big Boss
⚛ Hz
just use std::string and append it directly (if small enough like < 1MB
B121065_Swoyam Siddharth Nayak
バレンタインがいない柴(食用不可)
## Rules #pinned
* You are not entitled to an answer, getting angry about not answered questions will get you warned.
* Not checking your problem in google (or any other search engine) first will get you a warn.
* Asking to solve an assignment/test/whatever without trying it first yourself will get you a warn or will get you BANNED. We won’t write a code for you, but we can push you forward and suggest something.
* Before posting a long code snippet think twice and read the Resources section below.
* No “best book” or “best youtube channel” requests, use /get cbook and /get cppbookguide chat commands.
* No “best ide” requests, use /get ide chat command to see the suggestions.
* Asking for something that is in the pinned message right after joining WILL GET YOU BANNED.
* C/C++ discussion preffered (assembly also allowed), asking about other languages (or groups for other languages) right after joining will get you BANNED.
* Reverse enginnering, hacking and related topics are allowed, but asking to hack facebook, instagram, etc. is NOT allowed. Also if you ask "how to become a hacker" and obviously have zero knowledge on anything related to that you may get warned or banned.
* Legitimate requests for help on code and programming questions are welcome. A request is considered legitimate if it describes your problem, what you've done so far and what went wrong. Requests such as "write my program" or "do my homework" are never considered legitimate. Asking not legitimate questions will result in a warn or ban. See https://stackoverflow.com/help/mcve on how to write good questions.
* Asking for book recommendations is ok, but "pls give pdf book" is not allowed, find books by yourself. Posting illegally copied books (or links to those books) is also not allowed and will get you BANNED.
* Only English language is allowed, if you speak shitty English or don't understand anything in English YOU WILL BE BANNED.
* A little bit of programming related memes, jokes, shitposting are allowed.
* NSFW content (porn, nudity, etc.) is not allowed.
* Spamming/advertising (job posts are also ads, so ask an admin before posting) will grant you a warning or an immediate ban if you do it right after joining.
* Religion, politics and ideological topics are forbidden.
* Long code snippets must be posted via a snippet website(links below), posting pictures of code and posting long snippets in the group is not allowed.
* If you encounter a problem, while using dev C++ or turbo C/C++, you will not be helped, use another more modern IDE.
* Don't post compiled executables, that is obviously a security risk.
* Personal messages without asking beforehand are not allowed.
* If you want to post a link or some article in this chat you will need an admin approval first
## Resources
C/C++ group India: http://t.me/c_cpp_india
About asking good questions:
* [English](http://www.catb.org/esr/faqs/smart-questions.html)
* [Translations](http://www.catb.org/esr/faqs/smart-questions.html#translations)
For posting long code snippets:
* [GitHub Gist](https://gist.github.com)
* [Ubuntu Paste](https://paste.ubuntu.com/)
* [Pastebin](https://pastebin.com)
## Reports
If you notice any forbidden content, please use the /report command while responding to the offending post to report it to the admins.
I feel the rules are too straight... wouldn’t ban anyone for just asking questions.
That being said ...I however agree to what they try to achieve though. I’d also be pissed off if someone is just expecting an answer without thinking himself and just asking for granted. But we should be free to decide ourselves to ignore these kind of questions. We don’t really need to ban anyone here unless someone is making obvious harassment to others.
バレンタインがいない柴(食用不可)
My two cents.
ꍏꈤꀸ
バレンタインがいない柴(食用不可)
バレンタインがいない柴(食用不可)
😇
Ayush
I want to build a daily tracking app in c. Any resources you guys can point me to?
klimi
Ayush
klimi
Where to start
Write down things you expect it to do: features, design etc
Ayush
I want to start with an expense tracker cli based then move towards a gui later. Also can add daily task tracking to it aswell. Also some crypto support so that the data file cannot be read in plain text. Can also have an app lock for the current user. @K11M1
Sandeep
for (int i = 0; i < n - 2; ++i) {
int k = i + 2;👈👈
for (int j = i + 1; j < n; ++j) {
while (k < n && arr[i] + arr[j] > arr[k])
++k;
Sandeep
@
Someone runs c-90 programs on windows?
Puspam
Sandeep
Literally nothing
So it doesn't matter if I put that line in the first loop or the second loop??
Puspam
Sandeep
Starboard
Hi All
I am building project in C for library managment.
The issue is :
i have structure user like :
typedef struct member{
name s_name;
unsigned int id;
char *dept;
long mobile;
category cat;
}member;
typedef struct user{
member personal_details;
char* password;
}user;
I dynamically allotace memeory and store the strings data from user.
And i am writing this data to binary file using fwrite.
example : fwrite(new_user,sizeof(user),1,ptr_of_file);
But when later i access the struct members then they all give seg fault.
How should i solve this issue.
I have understood that issues is that we are just writing pointer and not whole data that has memory allocated.
How should i stored properly ?
⚛ Hz
it called serialization/deserialization
⚛ Hz
it is not a easy task,but you can start from here
+
just use std::string and append it directly (if small enough like < 1MB
as I said I have some files (max size 40MB)
what I want to do is open files make some changes (new change can be bigger or smaller then original data) and also for add new change I need to seek so many times in data, I mean first create a string buffer (by converting std::string to char by c_str()) then save the size of string before it, then get the size of buffer and after that append both of them on another buffer.
Starboard
Anonymous
Starboard
Okay got that thanks