Jacky
what’s the matter?
Jacky
Shubh
skip the second student name
Jacky
….., because it has too much newline character, u need to use the getchar() or other func to resolve
Jacky
u can see it in c primer plus, btw
Shubh
ok
I use Arch
Spirit
I think his message was pseudocode
Yeah basically. It seemed unimportant to add all the included and using statements. I think there was plenty of info to understand what was going on. And It was just an example of what I was trying to understand.
Set41
Hello, I need your help, I need your help. How can I convert this python programming code to C?
Set41
from numba import jit, cuda
import numpy as np
# to measure exec time
from timeit import default_timer as timer
# normal function to run on cpu
def func(a):
for i in range(10000000):
a[i]+= 1
# function optimized to run on gpu
@jit(target ="cuda")
def func2(a):
for i in range(10000000):
a[i]+= 1
if name=="__main__":
n = 10000000
a = np.ones(n, dtype = np.float64)
b = np.ones(n, dtype = np.float32)
start = timer()
func(a)
print("without GPU:", timer()-start)
start = timer()
func2(a)
print("with GPU:", timer()-start)
Ludovic 'Archivist'
shriman_deepak
Hey how to check if there's any space between string or not ?
shriman_deepak
I mean the proper syntax to use that function to check the space
Dr
shriman_deepak
Any syntax ?
shriman_deepak
Just for reference
shriman_deepak
I never used that
ARx
strings are like arrays of chars
string[i] == ' '
can be a good condition
Dr
Just for reference
Well I don't know any built in function to index any specific character from string, but as I said above for iterating through string, you can simply use for loop from i=0 to i=string.length()
And check if string[i] == ' '
Dr
lol i just tried and it worked... wait
Dr
string s = "Hello World!";
for (int i=0; i<s.length(); i++) if (s[i] == ' ') cout<<"Space Found!"<<endl;
dave
does anybody speak italian and can help me in c++ base things
anonymous
I wanna learn c++ from beginning
artemetra 🇺🇦
Anonymous
The best way to learn C as a first language is through a book as your first language is the hardest language
anonymous
Anonymous
They’re not comprehensive which is the problem
The
I am trying to compile my simple hello world app with via developer command line , but when add #include <string> to my test app throws many unliked externals
The
cmd used to compile: "cl /nologo /c /O1 test.cpp" -> "link /nologo /ENTRY:main /SUBSYSTEM:WINDOWS test.obj msvcrt.lib kernel32.lib user32.lib"
The
same app works fine if i compile on visual studio, so my guess cl.exe can't find standard libraries
The
what I doing wrong?
Anonymous
Anonymous
Don’t manually link the libraries
Anonymous
Install visual studio community 2022 or whatever is the latest version it comes with a compiler for c and c++
មួង អាទិត្យឆវ័ន្ត
/get
Anonymous
Hello people 👋
មួង អាទិត្យឆវ័ន្ត
sorry just accidently drop my mouse on comment
Dr
#india
Mr
...
You are required to write down a program to calculate the area and volume of an office using Object Oriented Programming with C++. You should use the Office class and its object office1 to calculate the area and volume of the office. In the main(), you should assign the values of length, breadth, and height with the code:
office1.length = 70
office1.breadth = 40
office1.height = 30
i. In the written program(s), demonstrate the use of both public and private members/objects of a class in the program(s). [8marks]
ii. Compile the program using a suitable simulator e.g. Code::Blocks and debug all errors and take a screen shot. [4marks]
Anonymous
Use msvc
cl is part of the msvc, wdym?
Anonymous
cli is but its hard to use cli on msvc its hell even trying to find where its located
Anonymous
Back when I used windows i used visual studio community 2019
Anonymous
/get rose_as_my_girlfriend
Anonymous
😳
Anonymous
Good morning
Anonymous
Anonymous
I'm not really sure if there are anyways to get MSVC compiler besides Visual Studio Community
Anonymous
Anonymous
DOS commands are hard to use for me
Anonymous
Anonymous
you can set it up manually with vscode
Anonymous
gcc is easier to use in my opinion
Anonymous
They have very similar flags ig, so not sure why u say that
Anonymous
gcc has too many flags to count lol
Anonymous
Also cl.exe has many
Anonymous
always have -Wall :)
Anonymous
its a linker like ld so yeah
Anonymous
https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options?view=msvc-160
Anonymous
found documentation on it cl controls C/C++ compiler
Anonymous
"You can start this tool only from a Visual Studio developer command prompt. You cannot start it from a system command prompt or from File Explorer. For more information, see Use the MSVC toolset from the command line." does this mean you have to install visual studio community?
Adarsh
#include<iostream>
#include<stdlib.h>
using namespace std;
struct node
{
int data;
struct node *next;
}*first;
void create(int a[],int size)
{
int i=0;
struct node *t,*last;
first=new node;
first->data=a[i];
first->next=NULL;
last=first;
for(i=1;i<size;i++)
{
t=new node;
t->data=a[i];
t->next=NULL;
last->next=t;
last=t;
}
}
void Display(struct node *t)
{
while(t)
{
cout<<t->data<<" ";
t=t->next;
}
}
int count(struct node *p)
{
int count=0;
while(p)
{
count++;
p=p->next;
}
}
void Insert(struct node *p,int position,int x)
{
struct node *t=new node;
t->data=x;
if(position<0||position>count(p))return;
if(position==0)
{
t->next=first;
first=t;
}
else
{
for(int i=0;i<position-1;i++)p=p->next;
t->next=p->next;
p->next=t;
}
}
int main()
{
int a[]={1,9,3,7,6,4,5,2,8};
create(a,9);
Display(first);
cout<<endl;
Insert(first,5,100);
Display(first);
cout<<endl;
return 0;
}
Adarsh
can anyone tell me my error i cannot insert a new node at any index other than 0
Spirit
#include<iostream>
#include<stdlib.h>
using namespace std;
struct node
{
int data;
struct node *next;
}*first;
void create(int a[],int size)
{
int i=0;
struct node *t,*last;
first=new node;
first->data=a[i];
first->next=NULL;
last=first;
for(i=1;i<size;i++)
{
t=new node;
t->data=a[i];
t->next=NULL;
last->next=t;
last=t;
}
}
void Display(struct node *t)
{
while(t)
{
cout<<t->data<<" ";
t=t->next;
}
}
int count(struct node *p)
{
int count=0;
while(p)
{
count++;
p=p->next;
}
}
void Insert(struct node *p,int position,int x)
{
struct node *t=new node;
t->data=x;
if(position<0||position>count(p))return;
if(position==0)
{
t->next=first;
first=t;
}
else
{
for(int i=0;i<position-1;i++)p=p->next;
t->next=p->next;
p->next=t;
}
}
int main()
{
int a[]={1,9,3,7,6,4,5,2,8};
create(a,9);
Display(first);
cout<<endl;
Insert(first,5,100);
Display(first);
cout<<endl;
return 0;
}
you should wrap code in triple backticks
Dr
#include<iostream>
#include<stdlib.h>
using namespace std;
struct node
{
int data;
struct node *next;
}*first;
void create(int a[],int size)
{
int i=0;
struct node *t,*last;
first=new node;
first->data=a[i];
first->next=NULL;
last=first;
for(i=1;i<size;i++)
{
t=new node;
t->data=a[i];
t->next=NULL;
last->next=t;
last=t;
}
}
void Display(struct node *t)
{
while(t)
{
cout<<t->data<<" ";
t=t->next;
}
}
int count(struct node *p)
{
int count=0;
while(p)
{
count++;
p=p->next;
}
}
void Insert(struct node *p,int position,int x)
{
struct node *t=new node;
t->data=x;
if(position<0||position>count(p))return;
if(position==0)
{
t->next=first;
first=t;
}
else
{
for(int i=0;i<position-1;i++)p=p->next;
t->next=p->next;
p->next=t;
}
}
int main()
{
int a[]={1,9,3,7,6,4,5,2,8};
create(a,9);
Display(first);
cout<<endl;
Insert(first,5,100);
Display(first);
cout<<endl;
return 0;
}
You aren't returning count in count function..
Simply add return count statement and it'll work
Dr
Also I read somewhere, you should use nullptr instead of NULL for pointers
Adarsh
thank you to both of you it is working fine now
I use Arch
NULL is 0. When you use 0 to set the value of pointer it automatically convertes to nullptr as I know
Anonymous
Anshul
Arvind
Arvind
I don't remember seeing a nullptr.
Anonymous
https://stackoverflow.com/a/20509811
Anonymous
But u can still use NULL/0