Anonymous
that is function
Libertas
int main() { int n = 26; char initialWord[100]; char alphabet[26] = "abcdefghijklmnopqrstuvwxyz"; char *shuffledAlphabet = shuffle(alphabet, n); printf("Initial alphabet: \n"); printArray(alphabet, n); printf("\n\nShuffled alphabet: \n"); printArray(shuffledAlphabet, n); printf("\n\nWrite word for encoding: "); scanf("%[^\n]s", initialWord); encode(&initialWord, shuffledAlphabet, alphabet, n); return 0; }
klimi
> char alphabet[26] = "abcdefghijklmnopqrstuvwxyz"; that's a mistake
klimi
Libertas: https://cplayground.com/?p=goshawk-hare-sandpiper actually that’s all code in a sandbox
Libertas
thanks
klimi
np
klimi
char alphabet[27]
klimi
str[i] means *(str+i)
Anonymous
oh man its language c and I search solution on c++
Libertas
Anonymous
many thing I ddnt understd
\Device\NUL
Also, your scanf is unsafe. Use max field width
Anonymous
Hello everyone, I just want to clear my confusion. Why are suffixes appended on numeric or floating-point literals when the compiler already knows what kind of data they hold based on the declaration of data types? I know that appending suffixes are required in expressions, but what are the advantages of adding one in initialization? Moreover, what are the advantages of doing that aside from explicitly stating that a literal is a particular data type. I have been researching for over 30 minutes now, and I only have a general understanding of it.
Anonymous
I don't get it
I mean, for example: long x = 3000000000L; Even if I remove the 'L' suffix, it will still work the same. So what's the point of adding the 'L' suffix at the end when it doesn't make any difference at all, at least in my experience. Therefore, what are the advantages of appending suffixes in numeric literals aside from being explicit? I'm sorry if it's confusing, English is not my native language. Thanks!
Anonymous
does the same concept in floating point types apply in int types as well? Where you have to append an 'F' or 'f' on a floating-point literal to make it a float data type instead of a double data type in default?
Евгений
Guys, is there a website with a bunch of examples of lambda? Thank for reply 🌹
Anonymous
You meant when you type: float a = 2.3. You should add 'f' after 2.3? Otherwise compiler will change it to double?
yes, does the same concept applies on numeric types as well? So when I declare a variable as a long, it will be still seen as an int value instead of a long value because long is technically an integer data type still? I really just want to hear someone's thoughts to clear this annoying confusion in my head. Anyways, thank you so much!
Евгений
Which resources d'you use for learning CPP?
Евгений
Anonymous
Which resources d'you use for learning CPP?
I have been learning C for a while, about a month I guess. And I had to slow my pace a bit so that I can thoroughly understand some concepts. The book that I have been using is the "C Programming: A Modern Approach" by K.N King.
Anonymous
I mean if you were referring to me
Евгений
I mean if you were referring to me
learncpp.com it's my recommendation for you. If you're English is good enough, you'll get it. Those guys often update the information. Very good explanation and examples.
Anonymous
Have you read this ? https://stackoverflow.com/questions/25291351/c-and-number-suffixes#25291399
Oh thanks! I haven't seen this yet. The explanation was clear and I now have a better understanding of it! Thanks
Евгений
do you know if there's a similar website like this but for C? Thanks btw!
I give you don't wanna use std::cout and std::cin, right?:)) in C++ you can use printf as well. It's much better than C.
J
I mean, for example: long x = 3000000000L; Even if I remove the 'L' suffix, it will still work the same. So what's the point of adding the 'L' suffix at the end when it doesn't make any difference at all, at least in my experience. Therefore, what are the advantages of appending suffixes in numeric literals aside from being explicit? I'm sorry if it's confusing, English is not my native language. Thanks!
That's mainly for readability. Also, it is useful when you use auto keyword. The main reason why numbers are suffixed. auto x = 3.04f; If I am checking if a floating number x is equal to 3.04 The compiler considers 3.04 as a double and return the result as false.(Since rounding of double is different from that of float). If I use if (x == 3.04f), 3.04 is considered as a float and it returns true
Eduardo
Hello, can someone help me with this exercise please? It is a record of books that is saved in a file and they ask me that in case you want to add a book that is already added (I have to verify it by the code) the quantities to be added must be added. How can I do that function? struct tl{ char title[30]; float price; int cod,amount; }; tl book; void write(); int main (int argc, char *argv[]) { write(); getch(); return 0; } void write() { char resp; ofstream asal; asal.open("A2.txt",ios::app); if(asal==NULL) { cout<<"failed to open"; getch(); } resp='S'; while (resp=='S'|| resp=='s'){ cout<<"enter code"; cin>>book.cod; cout<<"enter amount"; cin>>book.amount; cout<<"enter price"; cin>>book.price; cin.sync(); cout<<"enter title"; cin.getline(book.title,30); asal<<book.cod<<" "; asal<<book.amount<<" "; asal<<book.price<<" "; asal<<book.title<<endl; cout<<"want to enter another? s/n"; cin>>resp; } asal.close(); }
Anonymous
Can anyone explain term oop?
Pavel
Can anyone explain term oop?
https://en.wikipedia.org/wiki/Object-oriented_programming
Anonymous
Sir I tried many websites or videos content to understand this concept but i didn't. Please explain as simple as possible you can.
Anonymous
Every part😁
Dima
پویا رحیم
Hiii everyone! I've a question : I want to make a game w c++. Actually rubik's cube! Somebody told me u have to install OpenGL for graphics library. Is that right ? And what's the next step. What compiler should i download for windows ...
Anonymous
Also supports openGL
پویا رحیم
Durbadol
Thanks
HaiNahi
I am searching for an internship/job related to development * Have made a chess engine (rated 1427 ELO in CCRL) * Resconstruction of rendering pipeline of a video (generation of video game's frame images pixel by pixel which needed math) Both projects I made was in C language...
Anonymous
Code without indentation,I really want them to learn Python and feel the charm of indentation
🇷🇺 Ryan
Code without indentation,I really want them to learn Python and feel the charm of indentation
python blows. white space "indentation" is MISERABLE and GROSS.
Aero
You can indent with tabs, most code quality analysis tools will mark that as an error since the PEP 8 document states you should use 4 white spaces, but as long as you don't mix the two you can use either
Anonymous
lol
Luca
Can i define a macro by setting its value equal to a function? Something like: #ifndef INT_MIN #define INT_MIN std::numeric_limits<int>::min() #endif
Deves
Airport simulation code in c language i want can any one send me
klimi
Airport simulation code in c language i want can any one send me
Uh, why? Have you tried searching on github?
Deves
Uh, why? Have you tried searching on github?
yeah i did i didnt find can you help me in it
Deves
you have to do your own projects!
i did that i have the code but it is not compiling as expected
Deves
if u can help me i would be happy
klimi
yeah i did i didnt find can you help me in it
Hm. I haven't had the need for such program. Why do you need it? Is there a reason for it?
Deves
yeah it my assignment but i am unable to do it i have been trying to do it from last few weeks
klimi
Uh... Your assignment! I see. And because you didn't do it you asked for the c code here.
klimi
Don't you have tutors?
Anonymous
https://cs.android.com/android/platform/superproject/+/master:system/incremental_delivery/incfs/util/map_ptr.cpp https://cs.android.com/android/platform/superproject/+/master:system/core/libutils/FileMap.cpp my poor brain hurts trying to surmize how to port all this to standalone C++ library
Kevin
ios: :sync_with_stdio(0); cin.tie(0);
Kevin
ios: :sync_with_stdio(0); cin.tie(0);
Somebody please tell me , what does it mean?
Kevin
In C++
\Device\NUL
ios: :sync_with_stdio(0); cin.tie(0);
Disable sync with C stream and doesn't flush ostream before getting input from istream
Kevin
Disable sync with C stream and doesn't flush ostream before getting input from istream
Can you please explain this in a bit of simpler way , actually I'm a beginner 😅
Misagh
Somebody please tell me , what does it mean?
They do two different things: std::ios_base::sync_with_stdio(false) This will disable the synchronization between C and C++ streams. After disabling the sync, you can no longer mix cout and printf and expect correct results. std::cin.tie(nullptr) By default, cin is tied to cout. this means that before cin does something, it will flush cout. This command will disable that. so std::cout << 12; std::cin >> a; may ask for your input before printing anything. Both of these can lead to IO performance improvements.
\Device\NUL
Input/output can be a performance bottleneck in C++ programs. By default, the standard iostreams (cin, cout, cerr, clog, and their wide-character counterparts) are synchronized with the C stdio streams (stdin, stdout, stderr), so that reads from cin and stdin, or writes to cout and stdout, can be freely intermixed. However, this coupling has a performance cost, because of the buffering in both kinds of streams. In the pre-standard "classic" iostreams library, unsynchronized mode was the default. If there is no need for a program to make calls to both standard C streams and C++ iostreams, synchronization can be turned off with this line of code: std::ios_base::sync_with_stdio(false); If any input or output operation has occurred using the standard streams prior to the call, the effect is implementation-defined. Otherwise, called with a false argument, it allows the standard streams to operate independently of the standard C streams (§IS-27.4.2.4). Another standard default is to flush all output to cout before reading from cin, for the purpose of displaying interactive prompts to the application user. If this synchronized flushing is not needed, some additional performance can be gained by disabling it: std::cin.tie(0); Ref: https://www.stroustrup.com/Performance-TR.pdf
\Device\NUL
Hello, i have question. Which is one is effective ? type arr[x] = {0}; or type arr[x]; memset(arr, 0, sizeof(arr));
Dima
memset one, but that all is unsafe in some terms
\Device\NUL
memset one, but that all is unsafe in some terms
If we initialized some of array members (not all), the rest will initialized to zero. Where's the unsafe part ?