Talula
#include <stdio.h> #include <string.h> int main() { char str1[10]= "awesome"; char str2[10]; char str3[10]; strcpy(str2, str1); strcpy(str3, "well"); puts(str2); puts(str3); return 0; }
Anonymous
Use strncpy not strcpy
Ritu Raj
Ritu Raj
One is limited 😇😇
Anonymous
One is limited 😇😇
One is horribly insecure and should be avoided just to make good habits
Anonymous
Both are good!
Propaganda
Ritu Raj
I'm wondering why the second approach doesn't work. It seems natural that it should (it works with other data types)? Could someone explain me the logic behind this?
olli
I'm wondering why the second approach doesn't work. It seems natural that it should (it works with other data types)? Could someone explain me the logic behind this?
char s[100] = "abcd"; is identical to char s[100] = {'a','b','c','d'}. You cannot copy assign arrays hence the second example is not working.
Anonymous
When you have an array like char string[4] string is a pointer to the first element of the array So if the second did work you would be overwriting a pointer somewhere not the value it points to
olli
When you have an array like char string[4] string is a pointer to the first element of the array So if the second did work you would be overwriting a pointer somewhere not the value it points to
if string were a pointer to the first element the second would work! void foo() { char s[4] = "Hi!"; char * p = &s[0]; p = "whatever"; } string in your example is "array 4 of char" you cannot assign arrays, you can only initialize them
- Raymond
Can someone tell me whi should I chose if over switch? Which one is better to use in most cases?
- Raymond
Well I just found one answer; you can't use double with switch
olli
switch - case is more limited than if statements, but there is no general rule.
- Raymond
Then why would you even have switch, if you can already do everything needed and even more in if statements ?
olli
nani? why are we still using char array instead of std::string?
I assumed it was C, so there is no string Additionally I think it'd interesting to know how the language handles this initialization
Omkar
Hi
- Raymond
Quick question
- Raymond
#include <iostream> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; double BTCPrice = 10000.111; int main() { cout << BTCPrice << endl; cin.get(); }
- Raymond
Why does this show the result as 10000.1 ?
- Raymond
and not 10000.111 ?
olli
Why does this show the result as 10000.1 ?
because defaultfloat is probably set and the precision is set to 6, so there are 5 digits before and one after the decimal point if you want a fixed number of digits after the decimal point you should std::fixed as formatting
- Raymond
👍
Anonymous
Pls solve questions 1
Anonymous
Anonymous
Read the rules, we are here to help you, not for doing your homework
Anonymous
Show us where you are facing the problem
Anonymous
Anonymous
Can any one help me with gtk in c
Anonymous
I don't know how to change the size of fonts in gtk
Anonymous
I want to increase the size of fonts in the entry
Anonymous
I am new with gtk so I don't know much off it
Anonymous
Ok
Anonymous
Hi
Anonymous
Hi
Hey
klimi
Hi
Anonymous
Wt??
Jussi
Does anyone here know, why GPT partition GUID changes when I move the partitioned drive between PCs? I mean if I format a USB stick and plug it into another machine, the GPT GUIDs are different
Jussi
Sorry, it is an offtopic question
Anonymous
GUIDs are assigned once first time an OS encounters the disk, it doesn't changefor that specific system but will be different for different computers!
Anonymous
change for*
Anonymous
Hello guys
Anonymous
Lets say we have this array: array[]={1,2,3,4,5} How can we display this array like this: (1+2+3+4+5)
Anonymous
Ok sir
Jussi
GUIDs are assigned once first time an OS encounters the disk, it doesn't changefor that specific system but will be different for different computers!
But there must be some sort of "base GUID" of which the "final GUID" is derived from, right?
Jussi
I mean in the GPT partition table on the disk
Jussi
Why cant the system just use that one ffs
klimi
I don't think it changes tbh
Jussi
It does
Jussi
At least the corresponding UEFI GUID changes
Anonymous
Just print it
I did this but the output is not like I expected
Anonymous
It suppose to be (2+7+6+9+8)
klimi
But you don't print the parentheses
klimi
You need to have one before that for loop and one after forloop
klimi
And you have to check for the last character if it is last so you don't print +
Niveth Saran
Guys? Which IDE of C++ would you prefer for Competitive Coding?
BinaryByter
honestly?
BinaryByter
probably vim
klimi
probably vim
thats not IDE
BinaryByter
it kinda is
Dima
> vim > ide
Dima
Otumian
Hey.. how are you..
Otumian
It will be vac very soon.. I would like a suggestion on some c or c++ projects to work.. preferably c++
Mihail
It will be vac very soon.. I would like a suggestion on some c or c++ projects to work.. preferably c++
Maybe buy an Arduino or something. There's always something to do with those
Otumian
Oh not to forget, there must be adequate resources on it..
Pratik
Hey guys do u have syntaxes of cpp and java It's imp
Mat
Hey guys do u have syntaxes of cpp and java It's imp
Do you want all the syntax for java and cpp?