ברני
https://onlinegdb.com/rkZZ5jHtv
ברני
https://onlinegdb.com/rkZZ5jHtv
BTW I'm uselly doing that kind of calculation with while loop.. But friends told me that it's better to do for loop then while if not necessary.. So maybe Im missing Somthing on the for loop..
Ammar
https://onlinegdb.com/rkZZ5jHtv
Every function has its own variable scope. Meaning that variable with the same name in different function will be different variable. Except for global variables which are defined outside of the function. If you want to use int arr[SIZE] in NumGame function, where int arr[SIZE] variable is defined in main function, you need to pass it as an argument to NumGame so it receives the expected value. You will have to modify your function like this int NumGame(int arr[SIZE], int digit, int counter); Then in main function, you also need to pass arr when you call NumGame. In main function, the call will be: NumGame(arr, digit, counter); Now NumGame has the reference of int arr[SIZE] which is defined in main function. But you need to remove the int arr[SIZE] variable definition in the NumGame function. Since in the same scope you cannot have the same variable name.
ברני
Exactly, but the call to it must also pass the corresponding variable.
OK, and about the calculation in the function I did, how can I do a for loop that also reads the numbers the user wrote and also compare them to the numbers the users wrote in the array cells?
ברני
I understand I need to do a for loop inside the for loop but logcly im missing the way to connect them
Ammar
BTW I'm uselly doing that kind of calculation with while loop.. But friends told me that it's better to do for loop then while if not necessary.. So maybe Im missing Somthing on the for loop..
As long as the loop has the same logic and storage, for loop and while loop are the same. Moreover compilers nowdays are smart, optimization to the loop is done very nice.
Ammar
I don't really understand what are you going to do. But I think it is like: You have an input 1233 The output 1 appears 1 times. 2 appears 1 times. 3 appears 2 times. Is that right?
Vitalii
#include <stdio.h> #include <string.h> int main () { char arr[1000]; char *ptr1,*min; gets(arr); ptr1 = strtok(arr," "); min = ptr1; while(ptr1!=NULL) { min=(strlen(ptr1)>strlen(min)) ? min : ptr1; ptr1 = strtok(NULL," "); } puts(min); return 0; } Hey, I spent half of day doing that... can anybody give me idea how to do next thing: I need to print two words which have the smallest amount of letters from a string entered from the keyboard. I wrote a code just for choosing only one word. Actually I tried to google it, but i didnt find anything (
Ks
If you make an array that keeps the amount of letters of each word
Ks
Then you look for the ones that have the min letters
Ks
More like an struct
Anonymous
i cant find any example code of the Painters Algorithm
Vitalii
More like an struct
#include <stdio.h> #include <string.h> int main () { char arr[1000]; int amount[100]; char *ptr1, *min1, *min2; printf("Enter the string: "); gets(arr); ptr1 = strtok(arr," ."); min1 = ptr1; for(int i = 0; ptr1!=NULL; i++) { amount[i] = strlen(ptr1); if(i!=0 && amount[i-1]>amount[i]) { min1 = ptr1; } ptr1 = strtok(NULL," ."); } printf("\nFirst small word in the string: %s", min1); return 0; } Sorry, did i understand you right? Is it in this way?
Vitalii
That's actually for one "min", but I wanna understand if I do right
Anonymous
sry quick question how do I select the compiler / interpreter/ how to run a c++ code in vs studio I have gcc but the button doesn't appear in vs code
Anonymous
Can array and variable declaration be done inside for loop??
Andrey
Guys, can someone help me, have no idea how to resolve this. I write to terminal some commands that my program has to make: For instance, ./prog deleterow 1 deleterow 3 clearcol 1 2 How can pass through this commands? I have no idea how to solve it, because you can have multiple function arguments (like deleterow has 1 argument and clearcol has 2 arguments)
Andrey
Command line arguments
I understand that I have to work with argv, but how to solve this situation 🤔
Anonymous
I understand that I have to work with argv, but how to solve this situation 🤔
Should look at the docs or somewhere in stackoverflow I think , I've never used commandline arguments before.
Resul
Hello, Can someone help me?, have no idea how to resolve this.
Resul
The function sent to the head node will calculate the number of elements in the list if one-way connected if the number of elements is odd, it will delete one node from the beginning, and if it is even, it will delete one node from the end. Function name and parameter void remove(struct node **head){
Resul
Send a piece of code where ya getting error via a passing service as link
void remove(struct node **head) { while (1) { head = &( (*head)->next ); } struct node *to_free = *head; *head = (*head)->next; free(to_free); }
Apk
I mean is the output wrong or some runtime error
Resul
Why are you stuck here?
I could not continue. I could not find how to solve it.
Iakovos
Guys I have a question, I am trying to sort 2 arrays(one ascending and one descending) both using select sort. As I've read in some forums when choosing the ascending array to sort with select it should take more time to complete than with the descending one. For some reason my program in C does the reverse. Even if I coded it right it gives me the reverse results. For example I get: ASC time: 9.34 DESC time: 10.35 when it should be the other way arround Highly appreciate your opinion!
Iakovos
Because it has to do with how does selection sort works so it should sort a descending array faster than an ascending
Vlad
Isn't selection sort just picks min of the whole array-offset each time?
Apk
Isn't selection sort just picks min of the whole array-offset each time?
yeah exactly....it should work the same for both ascending or descending
Anonymous
Can someone suggest me good REST API libraries to bring S3(AWS storage) objects. My c++ code should run from a linux machine
Iakovos
yeah exactly....it should work the same for both ascending or descending
I agree with you but when you increase the size of the array for example 200.000 elements the completion time changes
Iakovos
Why does this happen?? I mean its kind of weird
Apk
Why does this happen?? I mean its kind of weird
does that happens in every case....like irrespective of how sorted the array is
Iakovos
does that happens in every case....like irrespective of how sorted the array is
I tried a random array , an ascendind and a descending Like this: a) 1,5,9,6,3,7 b) 1,2,3,4,5,6 c) 6,5,4,3,2,1 But imagine this with a lot of numbers The completion time for each look like this: a) 218.00sec b) 217.00sec c) 235.sec
Iakovos
I mean for a few numbers you can not see the difference because the selection sort is so quick, but when you give the array like 200000 elements you can see the difference as I mentioned above
Apk
perhaps it is related to how the code is being executed on a lower level rather than the sort itself
Iakovos
perhaps it is related to how the code is being executed on a lower level rather than the sort itself
It is so strange because when a friend of mine ran it with the same code he got the results I wanted Lower descending time and higher ascending
Vlad
It won't match exactly, because A: your program is not only currently being run in the OS, B: caching is a thing.
Vlad
So to properly test you would need to have a 3 runs of each or so and then take an average of three.
Mr.
How do you change word from upper case to lower case in C when accepting input from a user
Nasib
Hey any help me learn c# programming language
Vlad
Hey any help me learn c# programming language
/report pming without permission
Mr.
What is the cause of this error?
Vlad
forgotten '\n' or messed up scanf format?
Mr.
This is the code
Vlad
This is the code
when outputting strings via printf use this printf("%s", "your string");
Vlad
So printf's formatting won't bite ya in the ass
Mr.
How do you take multiple inputs from a user in c one after the other
Vlad
How do you take multiple inputs from a user in c one after the other
You input a whole string until '\n' then tokenize it by ' ' and sscanf on it
Mr.
Can i get an example?
Vlad
Vlad
I'm too lazy/don't care
Simon
Hey guys, can you give me advice please. I'm trying to build old project (I think VS10 originally) in VS19, and trying to fix issues one by one. And while I'm building project, it gives me warnings as errors, for example about noexept or arithmetic overflow. I have checked project properties, and "Treat warnings as errors" set to "No". I think there probably some mistake in project files, but I don't know how to research it, maybe someone saw it before. Thanks in advance 🤝
Anonymous
friends I was trying to find words in a sentence and I get the following problem It should show me only the drama categories and still impose other categories
Anonymous
Anonymous