I
Try char*
Are you saying I should try casting a single pointer instead? I just wanted to understand pointer to pointer cast, this is not my code.
Hadaward 'Solly'
Don't use double pointer at all. If you need better explanation, tell what dynamic string is supposed to achieve
Hadaward 'Solly'
Are you saying I should try casting a single pointer instead? I just wanted to understand pointer to pointer cast, this is not my code.
You can think of double pointer as a matrix. The logic behind it is virtually the same as [][]. The argv defines an array of strings char*[]
Hadaward 'Solly'
You can for example alloc 4 spaces for char* first and iterate with [] to alloc the actual char arrays
Hadaward 'Solly'
Avoid using double pointers as it's easier to get distracted about buffer sizes leading to segmentation faults
I
Don't use double pointer at all. If you need better explanation, tell what dynamic string is supposed to achieve
this is code from simple examples teaching C, this is how it's used: char **dynamic_str_1 = (char **)malloc(sizeof(char) * 8); if (dynamic_str_1 != NULL) { *dynamic_str_1 = "1234567"; printf("dynamic_str_1: %s\n", *dynamic_str_1); } Isn't this a mistake? the "1234567" string literal is allocated in stack, no?
Tribe
Any person how knows C programming should help me
I
I still don't get how void * can become char **
Ludovic 'Archivist'
I still don't get how void * can become char **
Think of any pointer type like an entry in the index of a book (your code is the book), those indices can refer to other indices (char** is an index entry that refers to a char* entry, that entry is itself another index entry that refers to a character)
Ludovic 'Archivist'
The entries in themselves a but a number. When you have a page number in a book, whenever it points to a normal page or a page that refers you to another page, it is still a page number. The content of your pointer is like that. malloc(sizeof(char) * 8) This returns enough "space" in your book to write a page number there, so you can fit any page number whenever it refers to a page on dragons, or a page on raflesia plants or a spot in the table of content because a page number for any of those is but a page number
Ибраги́м
https://github.com/CPPAlliance/url
I
So in that code example they've made a mistake, they are not writing the string to the allocated memory, the allocated memory is storing the address, correct?
Ludovic 'Archivist'
https://github.com/CPPAlliance/url
Noooooo it depends on booooooost ;=;
I
the guy in the course is saying "we are storing 7 character string in memory", but I put a bigger string there and I get no error like this char **dynamic_str_1 = (char **)malloc(sizeof(char) * 8); if (dynamic_str_1 != NULL) { *dynamic_str_1 = "1234589789789789767"; // printf("dynamic_str_1: %s\n", *dynamic_str_1); }
Ludovic 'Archivist'
I
Thank you for your help
miguelf03kai
hello guys! how you doing? i'm studying c++ and i found this following snippet #include <iostream> using namespace std; int main() { int a = 1, b = 2; int c = a << b; int d = 1 << c; int e = d >> d; cout << e <<endl; } and i coudn't understand why "e" have the value 0;
miguelf03kai
someone could help me understand that?
miguelf03kai
thanks in advance
Anonymous
Can I create an app using C++ compiler apk using my phone
Anonymous
Its possible
I mean output like normal app
Marcio
Sorry, e = 16 (base **10**)…
Marcio
if you shift 16 (base 10) more than 5 times you will have zero.
Marcio
>=5 times
Anonymous
Hi
Anonymous
Who have c pdf pls
Anonymous
Or who want to learn c lets learn together please
Marcio
EDx.org > C and Linux Program (7 courses with tests), in ‘free’ option
Marcio
Very good C course
Anonymous
Thanks
Marcio
Tikram
Anonymous
It aint free bro😢
Anonymous
Someone help me
miguelf03kai
Someone help me
https://www.netacad.com/courses/programming here have some C free courses
miguelf03kai
if you shift 16 (base 10) more than 5 times you will have zero.
thanks man, great explanation, now it's clear in my mind.
Natasha
Is this the correct code for binary search?? int main() { int arr[] = {10,20,30,40,56,60,65,69,89,99}; int i, n, value = 24; n = sizeof(arr)/sizeof(arr[0]); int lb = 0, ub = 9; for (i = 0; i < n; i++) { int mid = (lb + ub) / 2; if (arr[i] < arr[mid]) { ub = mid - 1; } else if (arr[i] > arr[mid]) { lb = mid + 1; } else if (arr[i] == arr[mid]) { return i; } } return -1; }
Natasha
No
Any fix? 🥲
Anshul
In your code you wanna search for value in array but you put a loop and you look for arr(i) which is absurd. Do it like this Take your lb as 0 and ub as n-1 And then iterate on the array until lb<=ub and in each iteration you reduce your search space by n/2, making the algorithm an O(logn) algorithm
Anshul
Inside each iteration you can put the code that you've written in for loop
mohammed
Hey guys I'm new in problem solving Can I have some help
mohammed
int main() { string myNames[] = {"Henry","Tom","Jafar","Alice","Bob","Cindy","Clara","untitled"}; vector<string> myvector (myNames, myNames+8); for (vector<string>::iterator i=myvector.begin(); i<myvector.end(); ++i) { if (find(myvector.begin(), myvector.end(), "untitled")<myvector.end() ) { myvector.at(1) = "untitled"; } } sort(myvector.begin(), myvector.end(), [](const string & a, const string & b) -> bool { return a < b; }); cout << "Sorted vector:"; for (vector<string>::iterator it=myvector.begin(); it!=myvector.end(); ++it) std::cout << ' ' << *it; return 0; }
mohammed
i want to make untitle apear at beginning after sorting
mohammed
will be thankful if anyone help
Pavel
i want to make untitle apear at beginning after sorting
Only "untitled" or any other string from small letter?
Pavel
i want to make untitle apear at beginning after sorting
I think you can change your comparator to something like return (a == "untitled" || (b != "untitled" && a < b)); or something like this
mohammed
*well
mohammed
Worked..thank you 🥰
عبد الله
hi , i have a question , can u please help me?
klimi
hi , i have a question , can u please help me?
you could have asked your real query instead of asking for help
عبد الله
ok thanks
عبد الله
the problem is , i can not take a picture
عبد الله
to show u
klimi
the problem is , i can not take a picture
you are making screenshot tool? or some camera app?
عبد الله
#include <stdio.h> int main(void) { unsigned int second = 2147483648U; prinft("Second: %u\n", second); }
عبد الله
output did not show the last U
عبد الله
why?
عبد الله
output showed just the numbers.
عبد الله
sorry, but im still a beginner
Anonymous
output showed just the numbers.
U just means its Unsigned
عبد الله
i understand, when i write a letters in unsigned int, they will show up
عبد الله
will not
عبد الله
just like this ?
Anonymous
Just remove the U at the end of the number
SMS
it is usually written in this way when numbers are used directly
Anonymous
it is usually written in this way when numbers are used directly
Nah, the output will be negative with u, it differs
klimi
i understand, when i write a letters in unsigned int, they will show up
by saying 12345U you are saying to the compiler that the type of the thing you entered is unsigned. It won't save the "U" into the number. It is just a number. That's why no U is being printed, if you want the U at the end, you will have to make some function that would print it for you
Marcio
It aint free bro😢
It’s free or payed, you choose