ברני
Not necessary. What input do you give it to reproduce the issue?
I tried on c programiz, and offline C on phone (I'm not home), on GDB it dose work, I want to check at home in VS..
Ammar
why deleting line 17 incurs undefined behavior?
Sorry for replying old discussion, this mystery has been answered here: https://stackoverflow.com/questions/65456297/linux-x86-64-fork-syscall-strange-behavior-against-c-standard-libc-file-i-o-key
Anonymous
send here
Is is more than 400 lines of code
ɴꙩᴍᴀᴅ
Is is more than 400 lines of code
Github repo? (Or similar)
Eturnus
Can anyone help me to understand a simple c program please I am unable to understand it
Eturnus
#include<stdio.h> int main() { int a ,b; printf("Enter the two four digit numbers:"); scanf("%2d %4d ",&a,&b); printf("the the two numbers are : %d and %d",a,b); return 0; } Output Enter the two four digit numbers:2345 5685 the the two numbers are : 23 and 45 [Process completed - press Enter]
Eturnus
This one
Tangent Alpha
Is is more than 400 lines of code
put it in a file or just send here the problematic part
Anonymous
put it in a file or just send here the problematic part
I do not have any problems. It works, the purpose is to share the code anyone can change it and post comments. I will publish my githut later.
Tangent Alpha
Dont know use of %2d and %4d in it Please explain
read decimal integer at most n characters wide
Anonymous
what's the code for?
It shuffles a card deck using stack data structure and then buys 5 cards. It uses the random function.
Anonymous
what's the code for?
Each card represents a number and then it represents a card from 1 to 52.
Anonymous
what's the code for?
The shuffleling part is the part that I thought it was interesting.
Anonymous
How can be read a txt file by using linked list queue from it?
Anonymous
I'd gladly take a peek
https://github.com/tonykr86/cprogramming/blob/main/poker
Nils
std::shared_ptr<User> new_user = std::make_shared<User(data)>; Why doesn't that work? (No viable conversion)
Igor🇺🇦
std::shared_ptr<User> new_user = std::make_shared<User(data)>; Why doesn't that work? (No viable conversion)
What is User(Data)? 🤔 That does not look like a type. Also you're missing ()
Ausir
Hi @JRandomGuy just to say I figured out how fork works, I was using it in the wrong way! Now I studied better fork and execvp syscall and now I can use them! Thank you a lot for the tips and the patience you had with me 🙏🏻 Happy New year to you and to you all guys!
Prometheus
Anyone have any suggestions on transferring an object from one vector to another? My thought was just to push back the object from the first vector onto the second one then remove it from the first. I found something referring to a move function in a google search but wasn’t sure what would be the most efficient/easiest to implement if it had to be done multiple times.
Nils
What is User(Data)? 🤔 That does not look like a type. Also you're missing ()
Had to change it to: std::make_shared<User>(data);
Prometheus
vector::operator[] returns reference. so why can`t you cast to rvalue?
I can. I just wasn’t sure if there was a reason it was suggested to use the move function online over something else.
Ahadu
Hey gays I am Epheson I chatted from Ethiopia and i learn c++ programming. And i am just happy for join this group
Prometheus
you can copy or move. there are no other options
Apparently there are “Another option (instead of std::move) is to use std::make_move_iterator and vector.assign()”. Just trying to figure out what’s the best to use over all.
Shaswat
Anyone can send data structures and algorithms note pdf pls??
Prometheus
this is moving
Yes, in the end they do move it and serve the same purpose lol. This doesn’t seem like it’s going to go anywhere. Thanks for the reply, though.
tartaerae
Hello guys, i found the code in C, written on a if else using an array. like this [i + 1] [i + 2]. I was confused for [i + 1] is it(the plus 1) are a math operation or.. how?
Eturnus
int i = 10, j = 20, k = 0; k = (++i) + (--i) + (j++); Please explain ne how compiler showing k=40 My calculation: K=(11)+(9)+(21) K=41
Emir
int i = 10, j = 20, k = 0; k = (++i) + (--i) + (j++); Please explain ne how compiler showing k=40 My calculation: K=(11)+(9)+(21) K=41
There is no sequence point in this expression. It's undefined behavior. https://stackoverflow.com/questions/22817517/do-parentheses-force-order-of-evaluation-and-make-an-undefined-expression-define
Anonymous
int i = 10, j = 20, k = 0; k = (++i) + (--i) + (j++); Please explain ne how compiler showing k=40 My calculation: K=(11)+(9)+(21) K=41
Kyuki ++i me phele value add hogi phir print vese hi same --i me hoga but j++ me phele value print hogi
Anonymous
Programmers var runtil = /Until$/, rparentsprev = /^(?:parents|prev(?:Until|All))/ , isSimple = /^.[^:#\[\.,]*$/, POS = jQuery.expr.match.globalPOS, // methods guaranteed to produce a unique set when starting from a unique set guaranteedUnique = { children: true, contents: true, next: true, prev: true }; jQuery.fn.extend({ find: function( selector ) { var i, l, length, n, r, ret, self = this; if ( typeof selector !== "string" ) { return jQuery( selector ).filter(function() { for ( i = 0, l = self.length; i < l; i++ ) { if ( jQuery.contains( self[ i ], this ) ) { return true; } } });
Kaan
Hi I have a question. I am writing a code that takes string input from user and if string is polindrom prints polidrom. I used for loop for reverse the string then I compared reversed string and normal string with strcmp. Everthing was fine up to this part but somethink went wrong after comparing whatever I choose for string strcmp returns -1
Kaan
Can anybody help?
Kaan
If it is okey I can paste my code
Kaan
void isPolidrom(char string[]){ int lenght=sizeof(string)*sizeof(string[0]); char reversedStr[lenght]; int j=0; for(int i=lenght-1;i>=0;i--){ reversedStr[j]=string[i]; j++; } printArray(reversedStr,lenght); printf("%d\n",strcmp(string,reversedStr)); if(strcmp(string,reversedStr)==0){ printf("Polindrom"); } else{ printf("Not polindrom"); } }
Igor🇺🇦
How do you have a word without string? Depends on how you represent the word
Kaan
Did you used char array or just char
Emir
Emir I did think like you but then I tried to print lenght in function and it printed Exact number
if u passed parameter as an array, it's just a basic pointer. So sizeof(string) is always 4 or 8 bytes. No matter how long the string is.
Emir
u can pass "blablablablablabla" to function, and print the lenght
Kaan
if u passed parameter as an array, it's just a basic pointer. So sizeof(string) is always 4 or 8 bytes. No matter how long the string is.
Hmm yes I tried with 5 element and it give 4 but why does sizeof(array) gives 4 always in functions?
Igor🇺🇦
You can use std container such as std::array or std::vector and use std::reverse.
Emir
Hmm yes I tried with 5 element and it give 4 but why does sizeof(array) gives 4 always in functions?
Because passing an array is not actually passing an array. It's passing an address. https://stackoverflow.com/questions/1461432/what-is-array-to-pointer-decay
Igor🇺🇦
What didn't you understand? Do you know what vector is? https://en.cppreference.com/w/cpp/container/vector Do you know reverse algorithm? https://en.cppreference.com/w/cpp/algorithm/reverse?
Tangent Alpha
void isPolidrom(char string[]){ int lenght=sizeof(string)*sizeof(string[0]); char reversedStr[lenght]; int j=0; for(int i=lenght-1;i>=0;i--){ reversedStr[j]=string[i]; j++; } printArray(reversedStr,lenght); printf("%d\n",strcmp(string,reversedStr)); if(strcmp(string,reversedStr)==0){ printf("Polindrom"); } else{ printf("Not polindrom"); } }
void isPalindrome(char* array, int length){ // length does not include \0 character at the end of the string int i; if(length == 1){ printf("Palindrome"); return; } for(i = 0; i < (length / 2 + 1); i++){ if(array[i] != array[length - i - 1]){ printf("Not a palindrome"); } } printf("Palindrome"); }
Kaan
KAAK -1 Not polindrom//this is my first output I give a string named KAAK and printed reversed string which KAAK then compared with strcmp and I got -1
Kaan
NAAK -1 Not polindrom//And this is my second output I named the string as KAAN and then program printed NAAK this is a proof my reverse part is working fine
Kaan
if(strcmp(string,reversedStr)==0){ printf("Polindrom"); }//This part in my code compares reversed string and string. I do not understand why it gives always -1
Mushe
/
Kaan
You're reversing string wrong.
But when I print it does not seem wrong
Emir
But when I print it does not seem wrong
can u put on the screen reversedStr
Igor🇺🇦
But when I print it does not seem wrong
Sorry, my mistake. I didn't notice that you increase j too.
Kaan
can u put on the screen reversedStr
NAAK//This is reversed string I am not getting input for now I just use a array char string[]="KAAN"; -1 Not polindrom
Kaan
has reversed string \0 at the end
I forgot that I should add \0 to end of strings.
Kaan
void isPolidrom(char string[],int size){ char reversedStr[size]; int j=0; for(int i=size-1;i>=0;i--){ reversedStr[j]=string[i]; j++; } reversedStr[j+1]='\0'; printArray(reversedStr,size); printf("%d\n",strcmp(string,reversedStr)); if(strcmp(string,reversedStr)==0){ printf("Polindrom"); } else{ printf("Not polindrom"); } }
Kaan
I changed my function but the it does not work
Tangent Alpha
I forgot that I should add \0 to end of strings.
you don't need to, just don't change the last index
Kaan
Okey I think I understood the mistake. Strings has \0 in the end and when I reversed the string KAAK it wasnt "KAAK" it was " KAAK" because of the last character of the string
Mahir
PIC C/PROTEUS hi my circuit 16f84A I have 3 buttons I want the LED to light up from top to bottom when I press the 1st button, the LED will light up from the bottom when I press the 2nd button I want it to be in the form of a blink when I press the 3rd button. Can anyone help?
Al
bro this has really few to do with c , you can program a pic directly in assembler plus if you do it in C you really need to know about pic registers .. this question is related to embedded systems
Al
no pvt pls
Mahir
sorry
Al
my suggestion is to ask in another channel
Al
more related to your needs
Al
is plenty of iot and embedded system channels