Anonymous
Hey, i have a C question, i have a word that i read from keyboard, and alpfabed as a string. I need to parse the word and to find what index is each letter in alphabet string, so i came with this decision
void *encode(char str[100], char alpha[26], char initialAlpha[26], size_t n) {
int Index;
int stringLength = strlen(str);
for (int i = 0; i < stringLength; i++)
{
for(int j = 0; j < n; j++) {
// printf("%d\n\n", strcmp(str[i], initialAlpha[j]) == 0);
if (strcmp(str[i], initialAlpha[j]) == 0)
{
// str[i] = alpha[j];
printf("%c ", alpha[j]);
}
}
}
printf("%s", str);
}
but it returns nothing to me and shows that str[i] and initialAlpha[j] are char but should be Char *
but when i add & in front of them error dissapear but it isn’t working as it should :c
what should i do?
where is int main
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
Libertas
klimi
char alphabet[27]
Libertas
Hey, i have a C question, i have a word that i read from keyboard, and alpfabed as a string. I need to parse the word and to find what index is each letter in alphabet string, so i came with this decision
void *encode(char str[100], char alpha[26], char initialAlpha[26], size_t n) {
int Index;
int stringLength = strlen(str);
for (int i = 0; i < stringLength; i++)
{
for(int j = 0; j < n; j++) {
// printf("%d\n\n", strcmp(str[i], initialAlpha[j]) == 0);
if (strcmp(str[i], initialAlpha[j]) == 0)
{
// str[i] = alpha[j];
printf("%c ", alpha[j]);
}
}
}
printf("%s", str);
}
but it returns nothing to me and shows that str[i] and initialAlpha[j] are char but should be Char *
but when i add & in front of them error dissapear but it isn’t working as it should :c
what should i do?
the whole problem is here, strcmp needs a char* and string is a char* but if i divide it and take only one character of this string, like str[i] // a
then it is a issue cause this char isn’t a char* anymore but if i use &str[i] it will take all word, not the character i need and implementation will be wrong as well
klimi
str[i] means *(str+i)
Anonymous
oh man its language c and I search solution on c++
Libertas
\Device\NUL
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.
\Device\NUL
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
Евгений
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
\Device\NUL
Евгений
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
J
Vlad
Anonymous
Can anyone explain term oop?
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.
klimi
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
Anonymous
Also supports openGL
پویا رحیم
Anonymous
Durbadol
Thanks
🇷🇺 Ryan
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
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
mito
Deves
if u can help me i would be happy
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
In C++
Kevin
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
Kevin
Kevin
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
thank you...naga-wangy..
\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