#Why this program not showing my output? is there any scanf for string that can help me

15 messages · Page 1 of 1 (latest)

native dust
#
fallen kelpBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

#

@native dust

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

versed shadow
#

Can you C&P your code here please?

fallen kelpBOT
#

```cpp
int main() {
return 0;
}
```

native dust
# versed shadow Can you C&P your code here please?

#include <stdio.h>
#include <string.h>
typedef long long ll;
typedef unsigned long long ull;

void sorted(char name[1000][11], int num[], int n);

int main() {
    int t, n; scanf("%d", &t);
    for(int i = 0; i < t; i++){
      scanf("%d", &n); char s[11], name[n][11];
    int num[n];
      for(int j = 0; j < n; j++){
        scanf("%[^#]#%d\n", name[j], &num[j]);
    }
    scanf("%s", s);
    sorted(name, num, n);
    printf("Case #%d: ", i+1);
    for(int j = 0; j < n; j++){
      if(!strcmp(s, name[j])){
        printf("%d", j+1);
        break;
      }
    }
    printf("\n");
  }
}

void sorted(char name[1000][11], int num[], int n){
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      if(num[j] > num[i]){
        // swap num
        int temp = num[i];
        num[i] = num[j];
        num[j] = temp;
        // swap name
        char tmp[11];
        strcpy(tmp, name[i]);
        strcpy(name[i], name[j]);
        strcpy(name[j], tmp);
      }
      
      else if (num[j] == num[i]){
        if(strcmp(name[j], name[i]) < 0){
          // swap name
          char tmp[11];
          strcpy(tmp, name[i]);
          strcpy(name[i], name[j]);
          strcpy(name[j], tmp);          
        }
      }
    }
  }
}
native dust
versed shadow
#

May have a look later, unless someone else chimes in.
Rn I have to take the dog out while there is still daylight here.

Naive thought:
I think that swapping can be done just by swapping out the string pointers, instead of doing deep memory copies.
That swapping probably ought to be a separate function, seeing as you do that in two places.

native dust
#

At first i use this code
https://onlinegdb.com/lRt15s_XD

Maybe you can find where's the error code

fallen kelpBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.

versed shadow
#

Okay, I read your assignment.
I think you've gone about this whole thing in a wrong way.

You need to collate each line from the input file into a struct.
Then reorder these as per the score and secondly as per the name.

versed shadow
#

@native dust do you still need help with this?
Sorry I never got back to you yesterday.

fallen kelpBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.