𝚁𝚒𝚝𝚎𝚜𝚑𝚝𝚑𝚎𝚋𝚎𝚊𝚜𝚝𝚋𝚘𝚢 O_o
consteval
nice
Rohit
Which programming should I choose if I want to earn heavy
Maxim
Adrian
/start@MissRose_bot
Adrian
Which library should I use to display something with encoding utf-8 that allows me to use special characters?
#include <?.h>
Ludovic 'Archivist'
Rose
Reported Manu [552765840] to admins.
Chat Boss
Igor Kozelskiy sent a code, it has been re-uploaded as a quote
I have a pretty big file of .md type of 139761 lines. My function readlines perfectly reads file of smaller sizes, but when reading this one it finds 139779 lines.
c
#include "strarray.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int readlines(FILE *file, StrArray *lines) {
char buffer[BUFFER_SIZE];
memset(buffer, 0, sizeof buffer);
while (fgets(buffer, sizeof(buffer), file)) {
buffer[strcspn(buffer, "\n")] = 0;
if ((str_array_append(lines, buffer)) < 0) {
str_array_terminate(lines);
return -1;
}
}
return lines->size;
}
int str_array_append(StrArray *array, const char *new_str) {
if (!array || !new_str) {
fprintf(stderr, "add_str: NULL pointer detected\n");
return -1;
}
char **strs_upd =
(char **)realloc(array->array, sizeof(char *) * (array->size + 1));
if (!strs_upd) {
perror("realloc failed");
return -1;
}
strs_upd[array->size] = malloc(strlen(new_str) + 1);
if (!strs_upd[array->size]) {
perror("malloc failed");
return -1;
}
strcpy(strs_upd[array->size], new_str);
array->array = strs_upd;
array->size++;
return array->size;
}
void str_array_terminate(StrArray *array) {
if (!array || !array->array)
return;
for (size_t i = 0; i < array->size; i++)
if (array->array[i])
free(array->array[i]);
free(array->array);
array->array = NULL;
array->size = 0;
}
Igor
No idea why it reads more lines than there're actually in file
klimi
Chat Boss
What's your strarray.h
Igor Kozelskiy sent a code, it has been re-uploaded as a quote
Function declarations
#ifndef STRARR_H
#define STRARR_H
#include <stdlib.h>
#include <stdio.h>
#define BUFFER_SIZE 2048
typedef struct _str_array_
{
char **array;
int size;
} StrArray;
int readlines(FILE *file, StrArray *array);
int str_array_append(StrArray *array, const char *new_string);
int str_array_insert(StrArray *array, size_t position, const char *new_string);
int str_array_drop(StrArray *array, size_t position);
int str_array_drop_range(StrArray *array, size_t start, size_t end);
int str_array_replace(StrArray *array, size_t index, char *replacement);
int str_array_replace_range(StrArray *array, size_t start, size_t end, StrArray *rrange);
void str_array_terminate(StrArray *array);
#endif // !STRARR_H
Never Spam Bot
Igor Kozelskiy is now approved by the group admin and can send messages without any restrictions
Function declarations #ifndef STRARR_H
#define STRARR_H #include <stdlib.h>
#include <stdio.h> #define BUFFER_SIZE 2048 typedef struct _str_array_
{ char **array; int size;
} StrArray; int readlines(FILE *file, StrArray *array); int str_array_append(StrArray *array, const char *new_string); int str_array_insert(StrArray *array, size_t position, const char *new_string); int str_array_drop(StrArray *array, size_t position); int str_array_drop_range(StrArray *array, size_t start, size_t end); int str_array_replace(StrArray *array, size_t index, char *replacement); int str_array_replace_range(StrArray *array, size_t start, size_t end, StrArray *rrange); void str_array_terminate(StrArray *array); #endif // !STRARR_H
See spam? Quote the spam message in the group and reply with /spam
Igor
Well, I found the mistake....
Buffer was too small (2k chars was not enough) to handle lines from the file
Nikhil
Any body need gaming code for c++
Ludovic 'Archivist'
Marce
elsahou
no
Ludovic 'Archivist'
/warn English only
Rose
User 😊 has 1/2 warnings; be careful!
Reason:
English only
Ludovic 'Archivist'
/warn English only
Rose
User Madhav has 1/2 warnings; be careful!
Reason:
English only
Rose
User Nikhil has 1/2 warnings; be careful!
Reason:
spam/ad
Nikhil
What
Nikhil
Please remove me
klimi
Nikhil
No
Nikhil
I can't
Nikhil
.
Nikhil
.
Rahul
Does anybody can do the coding for my website?
klimi
Rose
Psych
anyyy senior c programmerssss hereee????
Aze
can the result of an RNG system ever be the same
Aze
like could the result of a crash game be replicated such that it so similar to the results of the game itself
Aze
is there any possibility
Programmer
Suka
Aze
Don
yeah
Sam
Yeah
klimi
/warn repeated ad
Rose
User Rahul has 1/2 warnings; be careful!
Reason:
repeated ad
Shruti
Indian?
V22001
klimi
Read the rules
Unknown Bot
Emojis are not allowed? :(
Rose
User Malikzada Ahsan has 1/2 warnings; be careful!
Reason:
homework
Lemuel
Hi am new
Yurri
Hey all
Yurri
Is there any idea how to convert our website into a legal application?
klimi
GPU Governor
Hi am new
For messages like this, you should consider joining the C++ offtopic group
Fire
Rose
Hi am new
Offtopic discussions should be done in the C/C++ Offtopic group. Please take your discussion/questions there.
GPU Governor
GPU Governor
You will write the application with html, css, js. Then bundle it as a web view (web container)
GPU Governor
And since this is a c++ group, i will recommend you use Qt webview
Sharan
Any one want projects ping me
Sharan
Kayathri
Hello I need help in my c++ assignment urgent
klimi
Chat Boss
Kayathri Rayan sent a code, it has been re-uploaded as a quote
#include "include/Battlefield.h"
#include "include/BattleShip.h"
#include "include/Cruiser.h"
#include "include/Destroyer.h"
#include "include/Frigate.h"
#include "include/Corvette.h"
#include "include/Amphibious.h"
#include "include/Supership.h"
#include "include/Game_Setup.h"
#include "include/MovingShip.h"
#include "include/RamShip.h"
#include "include/SeeingShip.h"
#include "include/Ship.h"
#include "include/ShootingShip.h"
#include "include/Supership.h"
#include <iostream>
#include <fstream> // For file operations
using namespace std;
int main()
{
ofstream outFile("output.txt"); // Create output file
streambuf* coutbuf = cout.rdbuf(); // Save old buf
cout.rdbuf(outFile.rdbuf()); // Redirect std::cout to output.txt
Battlefield battlefield(15, 15);
cout << "Created battlefield" << std::endl;
battlefield.printBattlefield();
Battleship BattleShip("BattleShip", 1, 1, battlefield, 1);
Cruiser Cruiser("Cruiser", 13, 7, battlefield, 2);
Destroyer Destroyer("Destroyer", 7, 9, battlefield, 3);
Frigate Frigate("Frigate", 5, 11, battlefield, 4);
Corvette Corvette("Corvette", 9, 3, battlefield, 5);
Amphibious Amphibious("Amphibious", 11, 5, battlefield, 6);
Supership Supership("Supership", 5, 6, battlefield, 8);
battlefield.printBattlefield();
for (int step = 0; step < 22; step++) // step
{
cout << "Step " << step << "\n" << endl;
BattleShip.takeTurn();
battlefield.printBattlefield();
Cruiser.takeTurn();
battlefield.printBattlefield();
Destroyer.takeTurn();
battlefield.printBattlefield();
Frigate.takeTurn();
battlefield.printBattlefield();
Corvette.takeTurn();
battlefield.printBattlefield();
Amphibious.takeTurn();
battlefield.printBattlefield();
Supership.takeTurn();
battlefield.printBattlefield();
}
cout << "End of simulation" << endl;
cout.rdbuf(coutbuf); // Reset to standard output again
outFile.close(); // Close output file
return 0;
}
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x87): undefined reference to `Battlefield::Battlefield(int, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xc1): undefined reference to `Battlefield::printBattlefield() const'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xf7): undefined reference to `Battleship::Battleship(char const*, int, int, Battlefield&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x12d): undefined reference to `Cruiser::Cruiser(char const*, int, int, Battlefield&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x163): undefined reference to `Destroyer::Destroyer(char const*, int, int, Battlefield&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x199): undefined reference to `Frigate::Frigate(char const*, int, int, Battlefield&, int)'
anyone can help my code has no error but when I run it shows this output I don't know why its not running
Chat Boss
Kayathri Rayan sent a code, it has been re-uploaded as a quote
#include "include/Battlefield.h"
#include "include/BattleShip.h"
#include "include/Cruiser.h"
#include "include/Destroyer.h"
#include "include/Frigate.h"
#include "include/Corvette.h"
#include "include/Amphibious.h"
#include "include/Supership.h"
#include "include/Game_Setup.h"
#include "include/MovingShip.h"
#include "include/RamShip.h"
#include "include/SeeingShip.h"
#include "include/Ship.h"
#include "include/ShootingShip.h"
#include "include/Supership.h"
#include <iostream>
#include <fstream> // For file operations
using namespace std;
int main()
{
ofstream outFile("output.txt"); // Create output file
streambuf* coutbuf = cout.rdbuf(); // Save old buf
cout.rdbuf(outFile.rdbuf()); // Redirect std::cout to output.txt
Battlefield battlefield(15, 15);
cout << "Created battlefield" << std::endl;
battlefield.printBattlefield();
Battleship BattleShip("BattleShip", 1, 1, battlefield, 1);
Cruiser Cruiser("Cruiser", 13, 7, battlefield, 2);
Destroyer Destroyer("Destroyer", 7, 9, battlefield, 3);
Frigate Frigate("Frigate", 5, 11, battlefield, 4);
Corvette Corvette("Corvette", 9, 3, battlefield, 5);
Amphibious Amphibious("Amphibious", 11, 5, battlefield, 6);
Supership Supership("Supership", 5, 6, battlefield, 8);
battlefield.printBattlefield();
for (int step = 0; step < 22; step++) // step
{
cout << "Step " << step << "\n" << endl;
BattleShip.takeTurn();
battlefield.printBattlefield();
Cruiser.takeTurn();
battlefield.printBattlefield();
Destroyer.takeTurn();
battlefield.printBattlefield();
Frigate.takeTurn();
battlefield.printBattlefield();
Corvette.takeTurn();
battlefield.printBattlefield();
Amphibious.takeTurn();
battlefield.printBattlefield();
Supership.takeTurn();
battlefield.printBattlefield();
}
cout << "End of simulation" << endl;
cout.rdbuf(coutbuf); // Reset to standard output again
outFile.close(); // Close output file
return 0;
}
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x87): undefined reference to `Battlefield::Battlefield(int, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xc1): undefined reference to `Battlefield::printBattlefield() const'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xf7): undefined reference to `Battleship::Battleship(char const*, int, int, Battlefield&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x12d): undefined reference to `Cruiser::Cruiser(char const*, int, int, Battlefield&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x163): undefined reference to `Destroyer::Destroyer(char const*, int, int, Battlefield&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x199): undefined reference to `Frigate::Frigate(char const*, int, int, Battlefield&, int)'
Chat Boss
Kayathri Rayan sent a code, it has been re-uploaded as a quote
"#include "include/Battlefield.h""
#include "include/BattleShip.h"
#include "include/Cruiser.h"
#include "include/Destroyer.h"
#include "include/Frigate.h"
#include "include/Corvette.h"
#include "include/Amphibious.h"
#include "include/Supership.h"
#include "include/Game_Setup.h"
#include "include/MovingShip.h"
#include "include/RamShip.h"
#include "include/SeeingShip.h"
#include "include/Ship.h"
#include "include/ShootingShip.h"
#include "include/Supership.h"
#include <iostream>
#include <fstream> // For file operations
using namespace std;
int main()
{
ofstream outFile("output.txt"); // Create output file
streambuf* coutbuf = cout.rdbuf(); // Save old buf
cout.rdbuf(outFile.rdbuf()); // Redirect std::cout to output.txt
Battlefield battlefield(15, 15);
cout << "Created battlefield" << std::endl;
battlefield.printBattlefield();
Battleship BattleShip("BattleShip", 1, 1, battlefield, 1);
Cruiser Cruiser("Cruiser", 13, 7, battlefield, 2);
Destroyer Destroyer("Destroyer", 7, 9, battlefield, 3);
Frigate Frigate("Frigate", 5, 11, battlefield, 4);
Corvette Corvette("Corvette", 9, 3, battlefield, 5);
Amphibious Amphibious("Amphibious", 11, 5, battlefield, 6);
Supership Supership("Supership", 5, 6, battlefield, 8);
battlefield.printBattlefield();
for (int step = 0; step < 22; step++) // step
{
cout << "Step " << step << "\n" << endl;
BattleShip.takeTurn();
battlefield.printBattlefield();
Cruiser.takeTurn();
battlefield.printBattlefield();
Destroyer.takeTurn();
battlefield.printBattlefield();
Frigate.takeTurn();
battlefield.printBattlefield();
Corvette.takeTurn();
battlefield.printBattlefield();
Amphibious.takeTurn();
battlefield.printBattlefield();
Supership.takeTurn();
battlefield.printBattlefield();
}
cout << "End of simulation" << endl;
cout.rdbuf(coutbuf); // Reset to standard output again
outFile.close(); // Close output file
return 0;
}
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x87): undefined reference to `Battlefield::Battlefield(int, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xc1): undefined reference to `Battlefield::printBattlefield() const'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xf7): undefined reference to `Battleship::Battleship(char const*, int, int, Battlefield&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x12d): undefined reference to `Cruiser::Cruiser(char const*, int, int, Battlefield&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x163): undefined reference to `Destroyer::Destroyer(char const*, int, int, Battlefield&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x199): undefined reference to `Frigate::Frigate(char const*, int, int, Battlefield&, int)'
Never Spam Bot
Kayathri Rayan sent multiple messages that looks like a spam.
Why was my message deleted?
Spam deleted in this group: 3181
Suka
Kayathri Rayan sent a code, it has been re-uploaded as a quote
"#include "include/Battlefield.h""
#include "include/BattleShip.h"
#include "include/Cruiser.h"
#include "include/Destroyer.h"
#include "include/Frigate.h"
#include "include/Corvette.h"
#include "include/Amphibious.h"
#include "include/Supership.h"
#include "include/Game_Setup.h"
#include "include/MovingShip.h"
#include "include/RamShip.h"
#include "include/SeeingShip.h"
#include "include/Ship.h"
#include "include/ShootingShip.h"
#include "include/Supership.h"
#include <iostream>
#include <fstream> // For file operations
using namespace std;
int main()
{
ofstream outFile("output.txt"); // Create output file
streambuf* coutbuf = cout.rdbuf(); // Save old buf
cout.rdbuf(outFile.rdbuf()); // Redirect std::cout to output.txt
Battlefield battlefield(15, 15);
cout << "Created battlefield" << std::endl;
battlefield.printBattlefield();
Battleship BattleShip("BattleShip", 1, 1, battlefield, 1);
Cruiser Cruiser("Cruiser", 13, 7, battlefield, 2);
Destroyer Destroyer("Destroyer", 7, 9, battlefield, 3);
Frigate Frigate("Frigate", 5, 11, battlefield, 4);
Corvette Corvette("Corvette", 9, 3, battlefield, 5);
Amphibious Amphibious("Amphibious", 11, 5, battlefield, 6);
Supership Supership("Supership", 5, 6, battlefield, 8);
battlefield.printBattlefield();
for (int step = 0; step < 22; step++) // step
{
cout << "Step " << step << "\n" << endl;
BattleShip.takeTurn();
battlefield.printBattlefield();
Cruiser.takeTurn();
battlefield.printBattlefield();
Destroyer.takeTurn();
battlefield.printBattlefield();
Frigate.takeTurn();
battlefield.printBattlefield();
Corvette.takeTurn();
battlefield.printBattlefield();
Amphibious.takeTurn();
battlefield.printBattlefield();
Supership.takeTurn();
battlefield.printBattlefield();
}
cout << "End of simulation" << endl;
cout.rdbuf(coutbuf); // Reset to standard output again
outFile.close(); // Close output file
return 0;
}
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x87): undefined reference to `Battlefield::Battlefield(int, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xc1): undefined reference to `Battlefield::printBattlefield() const'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0xf7): undefined reference to `Battleship::Battleship(char const*, int, int, Battlefield&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x12d): undefined reference to `Cruiser::Cruiser(char const*, int, int, Battlefield&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x163): undefined reference to `Destroyer::Destroyer(char const*, int, int, Battlefield&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\USER\AppData\Local\Temp\ccKhsmA6.o:main.cpp:(.text+0x199): undefined reference to `Frigate::Frigate(char const*, int, int, Battlefield&, int)'
see your error msg, make sure that your library .h have implementation for used function, it can be in seperate .c/cpp file or seperate binary object/library. and your compiler need to pointed to those file.
Anshul
Do we have any such group for python(and other programming languages) as well?