Anonymous
Arrays have fixed size nonetheless
Shvmtz
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int ARRAY_LENGTH = 5;
// #define ARRAY_LENGTH 5
void printarray(int* myarray, int length)
{
for (int i =0; i < length; i++)
printf("%i, ", myarray[i]);
printf("\n");
}
int main(int argc, char** argv)
{
int a[ARRAY_LENGTH] = { 1, 2, 3, 4, 5 };
int b[ARRAY_LENGTH] = { 5, 4, 3, 2, 1 };
int* p = malloc(sizeof(int) * 15);
for (int i = 0; i < 15; i++)
p[i] = i;
int arglengths[argc];
for (int i = 0; i < argc; i++)
arglengths[i] = strlen(argv[i]);
p = realloc(p, sizeof(int) * 20);
printarray(a, ARRAY_LENGTH);
printarray(b, ARRAY_LENGTH);
printarray(p, 20);
printarray(arglengths, argc);
free(p);
}
Anonymous
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int ARRAY_LENGTH = 5;
// #define ARRAY_LENGTH 5
void printarray(int* myarray, int length)
{
for (int i =0; i < length; i++)
printf("%i, ", myarray[i]);
printf("\n");
}
int main(int argc, char** argv)
{
int a[ARRAY_LENGTH] = { 1, 2, 3, 4, 5 };
int b[ARRAY_LENGTH] = { 5, 4, 3, 2, 1 };
int* p = malloc(sizeof(int) * 15);
for (int i = 0; i < 15; i++)
p[i] = i;
int arglengths[argc];
for (int i = 0; i < argc; i++)
arglengths[i] = strlen(argv[i]);
p = realloc(p, sizeof(int) * 20);
printarray(a, ARRAY_LENGTH);
printarray(b, ARRAY_LENGTH);
printarray(p, 20);
printarray(arglengths, argc);
free(p);
}
Dynamic memory allocation
Anonymous
Watch/ read about it.
Shvmtz
Shvmtz
You got any error ? Like..
error: variable-sized object may not be initialized
Shvmtz
Okay.
So you initialized the size variable inside the main().
What if you initialize the SIZE variable(const) globally outside the main() and use that SIZE variable with array inside main() ?
Shvmtz
Yes. Maybe
Shvmtz
Can you share code ?
Newly
Hi guys this is regarding the Embedded C, can you please let me know. how to full load the internal clock.
Shvmtz
Okay
Shvmtz
I think.
If you initialize the array while declaring it, like:
int tab[siz]= {11, 22, 33};
This will produce some error.
Anonymous
how do i convert a pointer into a float, and then back into a pointer?
eg
TEX * tex;
// ...
tex = blah;
floatArray.push_back({0, FLOAT_TRUE, tex});
// ...
auto data = floatArray.back();
if (data.isTex == FLOAT_TRUE) {
setTex((TEX*)data.tex);
}
kartik
Egor
Muchas gracias...locura
Anonymous
Header file for all .....can anybody help me out
Anonymous
Its std byte ++ something...i forgot please help me anyone
Anonymous
Anonymous
Thankyou💗
Anonymous
Is there any disadvantage to use this ..?
Anonymous
Anonymous
Is there any disadvantage to use this ..?
It is most often a Precompiled header. But it is generally not a good idea to include header files that you dont need because it bloats up your code. People usually use this header file for competitive programming but it is not a standard header file and you wont find people using it in professional work.
Anonymous
Okay thankyou .❤️
Hanz
Hello, what is __LINE__ in C? i found it on a source in GitHub
Hanz
is that thing standard?
Hanz
ok i foudn it on the internet
Anonymous
#include <stdio.h>
int main()
{
float num1,num2;
float value;
char op;
printf("Enter an operator [d = /, m = *, a = +, s = - ]: ");
scanf("%c",&op);
printf("Enter a number: ");
scanf("%f", &num1);
printf("Enter another number: ");
scanf("%f", &num2);
if (op=='d')
{
value = num1/num2;
printf("Answer = %f", value);
}
else if (op == 'm')
{ value = num1*num2;
printf("Answer = %f", value);
}
else if (op == 'a')
{ value = num1+num2;
printf("Answer = %f", value);
}
else if (op=='s')
{ value = num1-num2;
printf("Answer = %f", value);
}
else
printf("Please try again...");
return 0;
}
Thank u
Anonymous
Here's a program to find largest from 3 numbers, No syntax errors in the code, but it doesn't work properly.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n1,n2,n3,max;
printf(" Input 3 values you want to compare\n");
scanf("%d %d %d", &n1, &n2, &n3);
if((n1>n2)&&(n1>n2)) max = n1;
else if((n2>n1)&&(n2>n3)) max = n2;
else max - n3;
printf(" largest value is %d", max);
return 0;
}
Hanz
Anonymous
Hanz
np
Anonymous
Hello, what is __LINE__ in C? i found it on a source in GitHub
They are just preprocessor macros.
_ _LINE_ _ - Current line number
_ _FILE_ _ - Current file name
_ _TIME_ _ - The time at which the current file was compiled
_ _DATE_ _ - The date the file was compiled
_ _func_ _ - Name of the current function.
Hanz
Anonymous
Write a c program to input an admission number,
marks of a module and display admission number with grade.
The grade is assigned as follows.
Marks >=75 A
Marks 65-75 B
Marks 55-65 C
Marks 45-55 S
Marks <45 F
#include <stdio.h>
int main()
{
int adnum,marks;
char grade;
printf("Enter your admission number ");
scanf("%d",&adnum);
printf("Enter your marks ");
scanf("%d",&marks);
if (marks >= 75) grade == "A";
else if (marks >= 65) grade == "B";
else if (marks >= 55) grade == "C";
else if (marks >= 45) grade == "S";
else grade == "F";
printf("your admission number is %d and grade is %c",adnum,grade);
return 0;
}
Grade isn't print correctly, anyone can solve it?
Anonymous
Anonymous
Kaddy
How do I take input from the standard input stream in the following manner?
I want the user to be able to input any number of characters, even 50,000 on the terminal before pressing enter. The number of input characters isn't fixed at the start. I don't want to store the input string, I just want to keep a count of how many characters are entered
Anonymous
Anonymous
Could you elaborate please…
istream_iteratot<char> inp(cin), end;
unsigned count = 0;
while(inp != end){
*inp++;
++count;
}
//count is the number of characters entered.
If you dont want to consider the enter key then break out of the while loop if the user entered '\n'
Anonymous
pastecode.io/s/r02i1175
So I have this recursive function that prints values from the given number till 1, decrementing by 1 each time.
Is there any way I can make the function return a vector consisting of the values instead of printing them?
I'm trying to avoid global variables.
Kaddy
Anonymous
//Write a program to input a character display the entered character is a vowel or not .
#include <stdio.h>
#include <stdlib.h>
int main()
{
char c;
printf("Enter a character \n");
scanf("%c", c);
switch(c)
{
case 'a': printf(" %c is a vowel", c);break;
case 'e': printf(" %c is a vowel", c);break;
case 'o': printf(" %c is a vowel", c);break;
case 'u': printf(" %c is a vowel", c);break;
case 'i': printf(" %c is a vowel", c);break;
default : printf(" %c is not a vowel", c);
}
}
Anonymous
Anonymous
Anonymous
Kaddy
Anonymous
Anonymous
Anonymous
Anonymous
Anonymous
Anonymous
Kaddy
Kaddy
Now that the doubt is cleared, just for conceptual clarity what exactly is the difference in way that cin and getchar() work for my question? If you replaced the while loop condition with
while(cin >> c)
an infinite loop follows so there's some fundamental difference in the way that cin and getchar() are operating… anyone knows how?
Kaddy
Hanz
no, any code you have worked on?
Ravi
https://pastebin.com/9PjW5RBD
It is returning null LinkedList, why so?
Anonymous
https://pastebin.com/9PjW5RBD
It is returning null LinkedList, why so?
<quote>
head = temp; //head will be nullptr here
for(auto i:arr)
    {
        temp = i;
        temp = temp->next;
    }
</quote>
This code is wrong. You want head to be the first node in the vector but instead you are setting head to nullptr.
Moreover the code in the for loop is wrong. You want a node's next node to be the element following it in the vector but instead you are using what was the next node in one of the two sorted lists which is wrong.
Anonymous
And why are you even using a vector? Doesnt it defeat the purpose of using a linked list in the first place? The sorted list can be created in place without using the vector by instead just manipulating the next pointers.
Ravi
Anonymous
Ravi
Anonymous
What is the mechanism behind the rand() and srand() functions??
Anonymous
Anonymous
Anonymous
Yes please!
Well there are many ways you can generate them. The simplest way would be a linear congruential generator.
You start with some number say a seed.
You could generate the first number by substituting seed for x in
(a*x+b) mod m where a,b and m are decided by the generator. Typically m is a very large prime number and a and b are less than m.
The next number is generated by substituting the previous generated number for x in the above equation.
That is why when you start with the same seed, you get the same sequence of random numbers. This is the simplest RNG and there are much better PRNGs in use. rand() doesnt use a Linear Congruential Generator btw.
Anonymous
Anonymous
C++ has a better support for random numbers btw (though it is lacking in many aspects still) as compared with C.
Official hooligan of Pius XII
g++, if you're on linux, it's probably installed already
Official hooligan of Pius XII
Anonymous
wtf?
error: cannot initialize return object of type
'VertexEngine::Triple<const char *, unsigned int, Diligent::ITexture *> *' with an lvalue of type 'VertexEngine::Triple<const char *, unsigned long, Diligent::ITexture *> *'
Cris
Anonymous
oh
Anonymous
rip my ide replaces size_t with unsigned long