Kaan
objects points to a location in memory
I dont think the problem is about pointers because when I add the values by myself like this there is no problem (Mail newMail={"Kaan","k","aaa","123","DEF"};)
Andrew
it depends if you want to use new statement or not
Andrew
i dont remember well the sintax but i think it should be like this Mail newMail{"Kaan","k","aaa","123","DEF"}; but you should use new stament
Pavel
Andrew
objectype *yourobject = new objectype{param1,param2};
Pavel
Because if it's a struct (not a pointer), then its memory is the memory of its members basically.
Kaan
And also how you check that it becomes NULL?
I tried to print a variable of mail strcut
Kaan
printf("%s",newMail->message);
Kaan
this is how I assign Mail newMail={senderAdress,getterAdress,subject,date,encryted};
Kaan
I am sure inside variable are not NULL
Kaan
I tried to print them also
z
I tried to print them also
Show your detailed code on that part please.
Pavel
And code of the struct itself
Kaan
char senderAdress[40]; printf("Enter your user mail adress:"); fflush(stdout); scanf("%s",senderAdress); char getterAdress[40]; printf("Enter the getter adress"); fflush(stdout); scanf("%s",getterAdress); char date[11]; printf("Enter the date:"); fflush(stdout); scanf("%s",date); char subject[20]; printf("Enter the subject:"); fflush(stdout); scanf("%s",subject); char message[250]; printf("Enter the message:"); fflush(stdout); scanf("%s",message); char encryted[250]; encryptTheMesage(encryted,message,returnTheLastIndexOfStr(message)); Mail newMail={senderAdress,getterAdress,subject,date,encryted}; char s[250]; //strcpy(s,newMail.message); printf("%s",&newMail->message);
Kaan
mail part: typedef struct Mail{ char senderAdress[40]; char recieverAdress[40]; char subject[20]; char date[11]; char message[250]; }Mail;
Andrew
Kaan
to be sure you must debug
Cant I be sure with printing them
Kaan
I will try
z
You may also need additional variable to store the length of your encrypted message. Arbitrary bytes must be handled in different way with C null terminated string.
z
You may need something like this. [Struct definition] typedef struct Mail{ char senderAddress[40]; char receiverAddress[40]; char subject[20]; char date[11]; char message[250]; size_t msgLen; } Mail; [Initialization] Mail newMail; strncpy(newMail.senderAddress, inputSenderAddress, 40); strncpy(newMail.receiverAddress, inputReceiverAddress, 40); strncpy(newMail.subject, inputSubject, 20); strncpy(newMail.date, inputDate, 11); memcpy(newMail.message, encryptedMessage, encryptedMessageLength); newMail.msgLen = encryptedMessageLength; // use newMail here
Thierry
is C99 row or column major?
Thierry
is the memory layout used by C99 row major or column major i.e. multi-dimensional arrays
Anonymous
There's no multidimensional arrays These are arrays of arrays
Thierry
exactely what i mean
Anonymous
I don't understand what you mean
Anonymous
If you picture arrays of arrays, you'll get answer to your question
Rushi
Can any one explain this recursive by babysteps I have wasted whole day but cannot understand If m1 is greater than m2, then median is present in one of the below two subarrays. a) From first element of ar1 to m1 (ar1[0...|_n/2_|]) b) From m2 to last element of ar2 (ar2[|_n/2_|...n-1])
Rushi
Here is the code if (m1 < m2)     {         if (n % 2 == 0)             return getMedian(ar1 + n/2 - 1, ar2, n - n/2 +1);         return getMedian(ar1 + n/2, ar2, n - n/2);     }
Rushi
Here is problem approach by 2 method https://www.geeksforgeeks.org/median-of-two-sorted-arrays/amp/
Rushi
If any one can explain I have wasted whole day to understand
CΞMİL
hi
CΞMİL
MY FRİENDS
Rushi
Hi
CΞMİL
Hi
THANK YOU
Rushi
THANK YOU
Can you tell above steps to solve
CΞMİL
I'm newer too
Anonymous
Hi
Hi
Rushi
Hi
Anonymous
Hi
Which programming language you know?
Rushi
C++
Anonymous
C++
Good
Rushi
I I'm doing in c++ Can you explain
H
You know?
Nope, because of that i ask for it
Rushi
Hello gc
Anonymous
Anonymous
That was me
Jaaa
Hello gc
Tesla🐲
Anonymous
Martin
Hi all. Is it the correct behavior for this snippet to print "step 3" only? c++ auto example() -> return_ignore { std::cout << "step1" << std::endl; co_await std::experimental::suspend_always{}; std::cout << "step 2" << std::endl; } int main() { example(); std::cout << "step 3" << std::endl; }
Martin
(Code yanked from https://luncliff.github.io/coroutine/ppt/[Eng]ExploringTheCppCoroutine.pdf) Is said it should print "step 1" and "step 3".(Page 32)
Anonymous
Hii, how can i count the words in a string in c?
Martin
Behavior is correct🙃 Should print 1 & 3; returns from suspend_always!
Thanks. Do you know what I may be doing wrong? Or is this is a compiler/libc++ bug?
Martin
I only got 3 when compiled from GCC 10.2
Aakash
Thanks. Do you know what I may be doing wrong? Or is this is a compiler/libc++ bug?
Maybe something with gcc! You may check here with clang. I’ve added cout to check with flow! It’s correctly working aka returning at Suspend. https://wandbox.org/permlink/LmgsDMkWeHokl5rC
Martin
Thanks a lot! I'll look into it and maybe file an bug report.
IAmMADMAX
1 2 4 7 3 5 8 11 6 9 12 14 10 13 15 16
IAmMADMAX
1 2 4 7 3 5 8 11 6 9 12 14 10 13 15 16
Can Anyone Understand me this pattern?
Monem
Int n = rand() % 2; If (n==0) { Do this } This will do the task 50% of the time. How to make it 30% of the time or 70% ? Thank you 🙏🏼
Monem
C
Aakash
Thanks a lot! I'll look into it and maybe file an bug report.
Check with build version status if your gcc was compiled with coroutines support. If so, compile with -fcoroutines to identify the attachment to program. Thereafter you may seek bug based upon your debug & output.
Anonymous
Greetings my fellow programmers
PLAUNIT
/*WAP to generate a magic square*/ # include <stdio.h> # include <conio.h> int main() { int n, i, j, c, a[9][9] ; printf("Enter the size of the magic square : ") ; scanf("%d", &n) ; if (n % 2 == 0) { printf("\nMagic square is not possible") ; goto end ; } printf("\nThe magic square for %d x %d is :\n\n", n, n) ; j = (n + 1) / 2 ; i = 1 ; for(c = 1 ; c <= n * n ; c++) { a[i][j] = c ; if(c % n == 0) { i = (i + 1); goto loop ; } if(i == 1) i = n ; else i = i - 1 ; if(j == n) j = 1; else j = j + 1 ; loop : ; } for (i = 1 ; i <= n ; i++) { for (j = 1 ; j <= n ; j++) { printf("%d\t", a[i][j]) ; } printf("\n\n") ; } end : ; getch() ; return 0; }
Anonymous
Guys Does anyone know why screen1 prints an extra char when executed?
Anonymous
#include<stdio.h> #include<stdlib.h> #include<string.h> void reverse(char*, char*); int main(void) { char str[15] = "Hello World"; char str2[strlen(str)]; reverse(str, str2); printf("original str: %s\nreversed str: %s\n", str, str2); return 0; } void reverse(char *str, char *str2) { char *ptr = &str[strlen(str)-1]; for(int i = 0; ptr >= str; i++, ptr--) { str2[i] = *ptr; } }
Anonymous
#include<stdio.h> #include<stdlib.h> #include<string.h> void reverse(char*, char*); int main(void) { char str[15] = "Hello World"; char *str2 = malloc(sizeof(str)); reverse(str, str2); printf("original str: %s\nreversed str: %s\n", str, str2); return 0; } void reverse(char *str, char *str2) { char *ptr = &str[strlen(str)-1]; for(int i = 0; ptr >= str; i++, ptr--) { str2[i] = *ptr; } }
Anonymous
the last code doesn't print the extra char idk why :S
Anonymous
But why the version without malloc prints an extra char?