Talula
Develop front-end software.
I wouldn't recommend doing Win32 development in C++ unless you're using Qt as a tool and if you don't know about Windows programming, Qt wouldn't be the right place to start... Try something like C#
Nobody🪲
#include<stdio.h> #include<math.h> int main() { float angle,sin,cos,tan; printf("enter an angle:/n"); scanf("%f",angle); //degree to radian// angle=angle*3.14/180; sin=sin(angle); cos=cos(angle); tan=tan(angle); printf("sin=%f cos=%f tan=%f\n",sin,cos,tan); return 0; }
Nobody🪲
whats wrong with this
Nobody🪲
Scanf
Thank u
H
Why does c have so many vulnerable functions in the standard library? Like today I learned that basic functions like printf and scanf are vulnerable to format string exploits and buffer overflows. Why aren't these functions rewritten so they can be secure?
H
Ok
n
Hi guys, I have a question, I'm trying to save names in a string table in my "change" function (*array[]) The problem is as soon as I want to increase the index of the stringtable, the debugger reports a threat and the program crashes please help me... i know if i set the variable "c"= '\0' the programm doesnt crash..... but i dont get why... could someone please explain why... I am a beginner so please dont be that rude😅😆 funciton // void change(char input[], char *list[]){ char *array[60]; int name = 0; int counter = 0; int c; for(int index = 0; input[index] != '\0';index++){ if(input[index] != '\n'){ c = input[index]; *(* (array + name) +counter) = c; counter++; } if(input[index] == '\n'){ name++; counter = 0; } } } and my input for the function are these names:Gunther Pruschke Milica Mohaupt Hannelore Christoph Inga Stadelmann Semra Christoph Karina Tlustek Leonhard Nette Birgitt Textor Hans-Helmut Rosenow Stanislaw Hartmann Arzu Trüb Valerie Geisler Agnieszka Bauer Friedl Scholz Emanuel Gierschner Erdmute Schmidt Carmela Sölzer Saskia Segebahn Karl-Wilhelm Kabus Gerda Heinrich Diethelm Heser Francesca Dörschner Horst-Dieter Geisler Fabian Rörricht Gero Speer Jann van der Dussen Waltrud Heinrich Friedl Losekann Nikola Oestrovsky Dennis Höfig-Klapp Ada Kraushaar Desiree Schäfer Silvana Hartmann Concetta Naser Tino Matthäi-Römer Maxim Schuchhardt Uschi Hauffer Rosel Klapp Brit Stahr Otto Bruder Käte Schmiedecke-Schleich Karl-Heinrich Kade Bettina Dobes Natalja Tröst-Thies Hartwig Scholz Dörte Ritter-Riehl Christa-Maria Spieß Ernst Adolph Jakob Segebahn Eva-Marie Stadelmann Cläre Scholz-Blümel Editha Hecker Denny Schuchhardt-Eberhardt Cordula Scholtz Jolanda Käster Dieter Hertrampf Catherine Ruppert Nikola Bärer-Tlustek Ioannis Mielcarek Henrik Rudolph
\Device\NUL
You can use max field width on both printf and scanf to limit buffer. Check what scanf return
\Device\NUL
But i prefer input string than convert it rather than check what scanf return
Anonymous
the scanf_s privated goods added by Microsoft
n
why is it unsafe? please explain
Anonymous
lol
Anonymous
#pragma warning(disable : 4996)
artemetra 🇺🇦
what's the point of using x & 0xFFFFFFFF in code? doesn't it just leave the bits as is? or am i missing something
Anonymous
I think it should be understood in combination with the actual code
...
what's the point of using x & 0xFFFFFFFF in code? doesn't it just leave the bits as is? or am i missing something
depends on the type of 'x', if it's larger than 32 bit, it doesn't leave them as is
Anonymous
I remember this operation can be derived to find out how many 1s there are in the binary of a number
Anonymous
using the & and |
n
ok guys i am more confused right now😂😅
...
does it trim them?
well, you're esentially cutting out every bit that is set in FFFFFFFF
...
I remember this operation can be derived to find out how many 1s there are in the binary of a number
it's a terrible idea to implement this yourself, use std::popcount instead
artemetra 🇺🇦
I think it should be understood in combination with the actual code
well i actually saw this in context of python code but i thought i'd post it here since a c++ chat might be more acquaint with bit operations
Anonymous
In fact, many things are very bad to realize by themselves
Anonymous
But I think it's also a good way to exercise ur thinking, not to build wheels repeatedly. lol
artemetra 🇺🇦
well i actually saw this in context of python code but i thought i'd post it here since a c++ chat might be more acquaint with bit operations
i saw it in combination with bitshifts (x << (32-n)) & 0xFFFFFFFF or here x0 = x & 0xFF x1 = (x>>8) & 0xFF x2 = (x>>16) & 0xFF x3 = (x>>24) & 0xFF
...
In fact, many things are very bad to realize by themselves
in this case especially, you're making it much harder for the compiler to optimize your code. there are cpu architectures that implement popcount as a instruction, lookup "nsa instruction" if you want to read up on some funny trivia :D
...
i guess it does in fact in case of & 0xFF just set bits after the 8th position to zero
well the second example just accesses the individual bytes, in c/++ you might aswell use a union for that
Anonymous
okk
artemetra 🇺🇦
okay, i think i got it, thank you guys
Anonymous
bit operation is still used in the embedded direction, such as stm32
Anonymous
😢I don't want to deal with bit operators at all
artemetra 🇺🇦
bit operation is still used in the embedded direction, such as stm32
i'm reverse engineering a mangled proprietary format so i need it a lot lol
Anonymous
lol
Anonymous
my major will be studied in the future, but I prefer software engineering
\Device\NUL
\Device\NUL
the scanf_s privated goods added by Microsoft
That thing is non standard but you can use this libc https://github.com/rurban/safeclib
\Device\NUL
Also in gcc you can fill array like 4) char x[16] = { [0 … 15] = 0 };
You don't need it tho, If you initialize only few of array member, the rest will automatically initialized to zero
\Device\NUL
Except for the memset , I agree that could be an alternate
%Nikita
You don't need it tho, If you initialize only few of array member, the rest will automatically initialized to zero
In this case yes! But it can become a useful thing when you need to initialize some parts of array, for example first half of array will be ‘A’, and second will be ‘B’ char x[100] = { [ 0 … 49 ] = ‘A’, [ 50 … 99 ] = ‘B’ };
Ольга
Hi there. I hope someone will tell. How to find the smallest number of an array from the end? I wrote the code but the location of the item is not determined correctly
Ольга
Share the code
https://onlinegdb.com/hrzfGT6y4
\Device\NUL
Also, Consider change your array. Variable length array is slow and dangerous. It could lead to Stack Overflow
Ольга
It is my task
Ольга
It is short what I want smallest=arr[0][0]; for(i=m-1; i>0;i--) { for(j=n-1;j>0;j--){ if(smallest>arr[i][j]) { smallest=arr[i][j]; smallrowloc=i; smallcolumnloc=j; } } } printf("Smallest element in array is %d in location arr[%d][%d]\n", smallest, smallrowloc, smallcolumnloc); return 0; }
Ольга
Uhm, I got correct output. What's your input ?
2row 3 columns 4 5 4 7 6 8 My output largest 8 [1][2] Smallest 4 [3245][-64578] This location Ritht is [0][2]
\Device\NUL
2row 3 columns 4 5 4 7 6 8 My output largest 8 [1][2] Smallest 4 [3245][-64578] This location Ritht is [0][2]
Nope, I got Enter number of row and column: 2 3 Enter arr[0][0]: 4 5 4 Enter arr[0][1]: Enter arr[0][2]: Enter arr[1][0]: 7 6 8 Enter arr[1][1]: Enter arr[1][2]: Entered 2D Array: 4 5 4 7 6 8 Largest element in array is 8 in location arr[1][2] Largest element in array is 8 in location arr[1][2] Smallest element in array is 4 in location arr[0][0]
\Device\NUL
Maybe your program doesn't goes intro branch, main.c: In function ‘main’: main.c:75:3: warning: ‘smallcolumnloc’ may be used uninitialized in this function [-Wmaybe-uninitialized] 75 | printf("Smallest element in array is %d in location arr[%d][%d]\n", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 76 | smallest, smallrowloc, smallcolumnloc); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.c:75:3: warning: ‘smallrowloc’ may be used uninitialized in this function [-Wmaybe-uninitialized] main.c:73:3: warning: ‘largcolumnloc’ may be used uninitialized in this function [-Wmaybe-uninitialized] 73 | printf("Largest element in array is %d in location arr[%d][%d]\n", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 74 | largest, largrowloc, largcolumnloc); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ main.c:73:3: warning: ‘largrowloc’ may be used uninitialized in this function [-Wmaybe-uninitialized]
Ольга
Nope, I got Enter number of row and column: 2 3 Enter arr[0][0]: 4 5 4 Enter arr[0][1]: Enter arr[0][2]: Enter arr[1][0]: 7 6 8 Enter arr[1][1]: Enter arr[1][2]: Entered 2D Array: 4 5 4 7 6 8 Largest element in array is 8 in location arr[1][2] Largest element in array is 8 in location arr[1][2] Smallest element in array is 4 in location arr[0][0]
Well, you did not change anything in the code? Because my way out is not like that. Why I do not know. Ty even with [0] [0] is not very suitable for me because I need to find the smallest from the end, ie in my case it is the second 4
babi
Explain array of structure with example
\Device\NUL
Explain array of structure with example
struct sr { //code } struct sr arr[x]
babi
Ok were is example
\Device\NUL
Ok were is example
That code was an example
babi
Don't understand
Ольга
😳 , Did compiler give you any messages ?
No, it is not like turn off I mean that two day ago result was fine but know I have problems with location
Ольга
No, it is not like turn off I mean that two day ago result was fine but know I have problems with location
Maybe if I start from the end I need to make not Smallrowloc=i; Maybe m-1 be better?
Vitalii
Hey, I have a question, whether it is necessary to allocate "size + 1" here at allocation of dynamic storage for a zero-character or simply "size" is enough? ... int size = strlen(someStr); char* s = new char[size]; or char char* s = new char[size + 1]; strcpy(s, someStr); 'cause it works in both cases...
Ольга
Hi there. Maybe someone will help. I don't understand why my sum is not declared if I wrote a function for it. I hope for help https://onlinegdb.com/lxmHbiY1Pp
Ольга
Someone can help now?
Ольга
Someone can help now?
I have one problem with code in C
klimi
you wrote suma not sum
Ольга
you wrote suma not sum
If you me?Thanks, but I have already solved that problem. Now I am faced with the fact that the code does not do what is needed. This code don't make sorting. But I think it everything was correct
Anonymous
how to write simple quadratic c program???
Anonymous
hi your welcome
Andrey
remove line 7