Anonymous
Maybe im wrong but your code looks fine, assuming head is already set to a pointer to a node instance. you should probably add sanity checks for that.
Anonymous
hey
Anonymous
#include <stdio.h> #include <conio.h> //To print sum, difference , product and remainder of two number int main() { int first; int second; printf("Enter 1st number\n"); scanf("%d",&first); printf("Enter 2nd number\n"); scanf("%d",&second); int sum, difference,product, remainder; sum=first+second; difference=first-second; product=first*second; remainder=first/second; printf("The sum of two number is %d\n,sum"); printf("The diffrence of two number is %d\n,difference"); printf("The product of two number is %d\n,product"); printf("The remainder of two number is %d\n,remainder"); return 0; }
Anonymous
Can anyone guide me to where do I start in programming basics
Anonymous
Hmm
hrb
hey so i just started learning c through a course called cs50 , is it a good course or not ?
Anonymous
i need whole string
Deleted this message by mistake: 𝕸: #include <iostream> #include <algorithm> #include <iterator> #include <regex> int main() { std::string data = "data|address|1|22|333" "newdata|address|1|22|33"; std::regex rgx(R"([a-zA-Z]+\|[a-zA-Z]+\|\d+\|\d+\|\d+)"); std::copy( std::sregex_token_iterator(data.begin(), data.end(), rgx, 0), std::sregex_token_iterator(), std::ostream_iterator<std::string>(std::cout, "\n")); std::cout << '\n'; //to get tokens separated by | rgx = R"([a-zA-Z]+|[a-zA-Z]+|\d+|\d+|\d+)"; std::copy( std::sregex_token_iterator(data.begin(), data.end(), rgx, 0), std::sregex_token_iterator(), std::ostream_iterator<std::string>(std::cout, "\n")); } Just changed the regex expression to escape the | symbol. You also need to pass in 0 to the token_iterator constructor to get a full match. You were passing -1 which will get a non matching token instead
hrb
Do ur labs and problem sets
can u please explain I'm new to this
Anonymous
#include <stdio.h> #include <conio.h> //To calculate the area of circle #define PI 3.141 int main () { float PI, radius; printf("Enter radius of circle:\n"); scanf("%f",radius); float area = PI*radius*radius; printf)("The area of Circle is %f"",area); return 0; }
hrb
what do u mean by labs and problem setes
hrb
sets
Anonymous
what do u mean by labs and problem setes
Laboratory work, Probelm Set
Deepak
Anyone knows how to write code for Bisection method (Numerical method) in C or C++ Plz reply
Deepak
yes, someone knows
How to write can u help me I didn't know much in programming
Talula
How to write can u help me I didn't know much in programming
Start and ask for help... don't ask others to start for you.
Deepak
Ok
Anonymous
I'm computer scientist and learning cyber security now i want to create powerful cyber army i mean to work hacking and coding relating projects if any of you are interested message me!
Anonymous
😂😂
what ?
Anonymous
regardless of what i enter as input i always get 1 as the result; why is that? #include <iostream> using namespace std; char eq[] = ""; int main() { cin >> eq; int eq_elements = sizeof(eq)/sizeof(char); cout << eq_elements << endl; return 0; }
Anonymous
char is 1 byte(sizeof(eq)) and u divide it on(sizeof(char)) which is 1 byte too. 1/1 = 1
i'm trying to get the size of an array here! the array has multiple char elements!
Marián
Eyo, quick question I'd appreciate if someone with more experience could answer to... does MSVC actually parse the .vcproj files? or is it some kind of extension thing? - my point is, can I somehow run C++ project generated by visual studio with all it's .sln and .vcproj files under non-visual studio environment eg. linux running msvc?
Golden Age Of
regardless of what i enter as input i always get 1 as the result; why is that? #include <iostream> using namespace std; char eq[] = ""; int main() { cin >> eq; int eq_elements = sizeof(eq)/sizeof(char); cout << eq_elements << endl; return 0; }
perhaps your compiler doesnt give you an exception, cuz init like char eq[]="" mustnt work try something like this char eq[5]; for (size_t i = 0; i < 5; i++) { cin >> eq[i]; }
Phil
Hey, does someone have ressources or can explain me how to correctly include a librairy, how to avoid redifinition when I call mutiple times the same lib but in different .c files ??? main.c <-- "alpha.h" + "beta.h" beta.c <-- "alpha.h" cc main.c alpha.c
Anonymous
Redifinition gets prevented by include guards. For "installing" a library corrently into your project a build pipeline like make or cmake are usually used.
Anonymous
#pragma once should be implemented in most compilers by now. So you can just write that at the beginning of your header files to avoid redefinitions
Anonymous
Think "the cherno" has a really good video explaining linking in detail, you might want to watch that on youtube, i feel like he can explain things better than i could
Anonymous
Btw. i got a question 😅. Is there any workshop or anything related to windows driver development. All things i find are extremely dry and not well structured
'''''''
#include<stdio.h> struct Status { unsigned int bin1:4; unsigned int bin2:2; }; int main() { printf("Size of structure is %lu\n",sizeof(struct Status)); struct Status s1; s1.bin1=-4; s1.bin2=2; printf("%d %d",s1.bin1,s1.bin2); return 0; } why does it print 12 for s1.bin1 ?
Anonymous
Are you familiar with the twoth complement? I hope i translated that right^^
Anonymous
in essence you got a numeber -4 and have 4 bits to store the information. So the positive 4 should be: 0100 complement: 1011 twos (plus 1): 1100 which is 12 interpreted as unsigned value
Anonymous
However it should still print -4 if im not mistaken as the printf %d specifier interprets the stored value as a signed number. Although im not sure if it respects the storage limitation or if it reads 4bytes anyways. Would have to test that
Anonymous
the twos complement gets used in most programming languages to store negative numbers because it has some cool algebraic properties
Anonymous
Okay, interesting 😅
systemQuery
I have made a simple hello world program in c++ with cmake and m facing issue
systemQuery
When I open cmake file in VS 2019 and try to edit thr file, it gets hang and not responding In the end I have to close and reopen the VS Anyone have any idea for this...??
systemQuery
Still same issue
Anonymous
#include<stdio.h> struct Status { unsigned int bin1:4; unsigned int bin2:2; }; int main() { printf("Size of structure is %lu\n",sizeof(struct Status)); struct Status s1; s1.bin1=-4; s1.bin2=2; printf("%d %d",s1.bin1,s1.bin2); return 0; } why does it print 12 for s1.bin1 ?
Since your bit fields have unsigned type, assigning an out of range value to them results in a modular operation (wrap around) on them. So an unsigned bit field of length 4 can store only the values 0 to 15. When you assign -4 to it, the result is actually 2^4 - 4 that is 12. [<out of range value> + 2^4)%(2^4)] If your bit fields were signed, then assigning an out of range value to them is an implementation defined Behavior. So each implementation must document what it does when you assign an out of range value to a signed bit field.
Typing...
I am getting two errors one is g++.exe has stopped working and another one is collect2.exe has stopped working. Please help me.
Lion
why is the size of struct 4 bytes? as we reserve ( 4+2)bits, it must be 1 byte right?
Bitfields are slices of variables of the type what it declared
Lion
They are unsigned ints, therefore they are ONE 4-byte integer in total..
DEV 7
Best course for dsa Apna college or coding ninjas
Digvijay Singh
Hi
Anonymous
there's something called "debug"
Swati
class test{ int t; public: test(int n):t(n) { cout<<"value is"<<t<<endl; } void show() { cout<<t; } }; int main() { test t1(10),t2(50),t3(3); vector<test> v; v.push_back(t1); v.push_back(t2); v.push_back(t3); vector<test> ::iterator i= v.begin(); for(;i!=v.end();++i) cout <<(*i)<<endl; return 0;
Anshul
#include<iostream> #include<vector> using namespace std; class test{ int t; public: test(int n):t(n) { cout<<"value is"<<t<<endl; } void show() { cout<<t<<endl; } }; int main() { test t1(10),t2(50),t3(3); vector<test> v; v.push_back(t1); v.push_back(t2); v.push_back(t3); vector<test> ::iterator i= v.begin(); for(;i!=v.end();++i) (*i).show(); return 0; }
Anshul
you can do this as well
Anshul
You're welcome
Anonymous
joe
Excuse me guys Can any one teach e about functions in c in detail
joe
I know about it surfacely only
Anonymous
Excuse me guys Can any one teach e about functions in c in detail
There also isn't much to it really. Most in depth thing is probably calling conventions(and how the stackframe for that function gets build), how they get linked and possibly how to handle function pointers. If you know what arguments, scopes and return values are, you likely know enough for most purposes already. Correct me if im wrong
Shakel
Now i just find small projects of C to start my coding in C
Small
👋
Anonymous
Anonymous
Games are always fun 🤷‍♂️
Agreed. Recently I discovered even doing very simple games is fun
Anonymous
exactly 🤓