-5

Hi I am trying to right a program but am having so much difficulty. The program is a challenge I made up myself. I want to read in 6 strings from the user. Then I want to create a function that will allow me to compare those strings to find which string is different in size. Then I want to pass this info to another function that will determine the string length of the string that is different. Finally print the value. Here is what I have done thus far (many many errors).

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char* diffFun(char* ,char*,char * ,char *,char * ,char *)
    {
    char *s1;
    char *s2;
    char *s3;
    char *s4;
    char *s5;
    char *s6;
    char *result;
    if (strcmp(s2,s3,s4,s5,s6)<strcmp(s1))
            result =  s1;
    else if (strcmp(s1,s3,s4,s5,s6)<strcmp(s2))
            result s2;
    return result;
    }

int main()
    {
    char *str1;
    char *str2;
    char *str3;
    char *str4;
    char *str5;
    char *str6;

    printf("Give me a string1:\n");
    str1 = readString(stdin);
    printf("Give me a string2:\n");
    str2 = readString(stdin);
    printf("Give me a string3:\n");
    str3 = readString(stdin);
    printf("Give me a string4:\n");
    str4 = readString(stdin);
    printf("Give me a string5:\n");
    str5 = readString(stdin);
    printf("Give me a string6:\n");
    str6 = readString(stdin);

    char *cond;
    cond = diffFun((char* str1,char* str2,char* str3,char* str4,char* str5,char* str6);
    printf("%ls",cond);

    return 0;
    }
Fernando
  • 1,382
  • 8
  • 17
  • `readString()`?? is that a user defined function?? – Haris Oct 20 '14 at 13:47
  • What are the errors? Also show us the minimum code not all of it. What is the function call to diffFun meant to do what are the char* inn that line meant to do? Which tutorial are you working from? – mmmmmm Oct 20 '14 at 13:48
  • you should not repeat the type of variables when calling a function. Also you have there double "("... you might be confused by unintialized variables when the function has anonymous arguments and declare local variables inside the function... what should it mean strcmp with one or five arguments? – V-X Oct 20 '14 at 13:50
  • Im new to programming so I am so lost. These are my errors: pract.c:5: error: parameter name omitted pract.c:5: error: parameter name omitted pract.c:5: error: parameter name omitted pract.c:5: error: parameter name omitted pract.c:5: error: parameter name omitted pract.c:5: error: parameter name omitted pract.c: In function ‘main’: pract.c:32: warning: assignment makes pointer from integer without a cast – Maizy Pappas Oct 20 '14 at 13:54
  • pract.c:34: warning: assignment makes pointer from integer without a cast pract.c:36: warning: assignment makes pointer from integer without a cast pract.c:38: warning: assignment makes pointer from integer without a cast pract.c:40: warning: assignment makes pointer from integer without a cast pract.c:42: warning: assignment makes pointer from integer without a cast pract.c:45: error: expected ‘)’ before ‘str1’ pract.c:45: error: expected expression before ‘;’ token pract.c:49: error: too few arguments to function ‘diffFun’ pract.c:49: error: expected ‘;’ before ‘}’ token – Maizy Pappas Oct 20 '14 at 13:54
  • Where are variable name in function definition 'diffFun'?? Does strcmp take other than 2 arguments?? Where is 'readString' defined?? – Shreyash S Sarnayak Oct 20 '14 at 13:59
  • readString should be a built in function – Maizy Pappas Oct 20 '14 at 14:02
  • And add the error message to the question (use the `edit` button) – matsjoyce Oct 20 '14 at 14:05
  • I did. They are in the comments above. There are a lot – Maizy Pappas Oct 20 '14 at 14:08
  • 2
    You probably should gather some basic knowledge of the C language. – Jabberwocky Oct 20 '14 at 14:20
  • I have tried that and it just pops up a whole new list of errors @user3121023 – Maizy Pappas Oct 20 '14 at 14:28
  • these are just some of them @user3121023 error: ‘s1’ redeclared as different kind of symbol pract.c:5: error: previous definition of ‘s1’ was here pract.c:8: error: ‘s2’ redeclared as different kind of symbol pract.c:5: error: previous definition of ‘s2’ was here pract.c:9: error: ‘s3’ redeclared as different kind of symbol pract.c:5: error: previous definition of ‘s3’ was here pract.c:10: error: ‘s4’ redeclared as different kind of symbol pract.c:5: error: previous definition of ‘s4’ was here – Maizy Pappas Oct 20 '14 at 14:28
  • diffFun returns a large string lexicographically in the string is the longest length of the string? – BLUEPIXY Oct 20 '14 at 14:36
  • What **excatly** is `readString` ? There is no such builtin function in C. Show us that function, it is probably as messsed up as the rest of your program. – Jabberwocky Oct 20 '14 at 14:38
  • Try to start coding in increments, starting with a few lines, checking if it compiles and works, and then add more complexity in little steps always trying to compile every few lines (at least as you learn). – Fernando Jan 08 '15 at 03:23

1 Answers1

0

I do not understand well, but I feel like the following...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char* diffFun(int n, char *s[n]){
    int i, j;
    char *result = s[0];
    size_t result_len = strlen(result);

    for(i = 1; i < n; ++i){
        size_t len = strlen(s[i]);
        if(result_len < len){
            result = s[i];
            result_len = len;
        } else if(result_len == len && strcmp(result, s[i]) < 0){
            result = s[i];
        }
    }
    return result;
}

int main(void){
    char *str[6];
    int i;
    for(i=0;i<6; i++){
        printf("Give me a string%d:\n", i+1);
        str[i] = readString(stdin);
    }

    char *cond = diffFun(6, str);
    printf("%s",cond);

    return 0;
}
BLUEPIXY
  • 39,699
  • 7
  • 33
  • 70