title: error converting java code to string -transferring result from function
body: <p>I'm trying to convert a Java code I wrote to C, I just started learning C and I confuse it with Java.</p>
  
  <p>My java Code:</p>
  
  <pre><code>public class Biggest 
  {
    private static int testsExecuted = 0;
    private static int testsFailed = 0;
  
    public static void main(String[] args) 
    {
      System.out.println("Testing typical cases, including punctuation\n");
      testLongestWord("the quick brown foxes jumped over the lazy dogs", "jumped");
      testLongestWord("hello world she said", "hello");
      testLongestWord("Hello\tworld\tshe\tsaid", "Hello");
      testLongestWord("HELLO, world she said", "HELLO");
      testLongestWord("hello world! she said???", "hello");
      testLongestWord("\"hello world!\", she said.", "hello");
      testLongestWord("easy as abc123", "abc123");
      testLongestWord("easy as abc,123", "easy");
  
      System.out.println("\nTesting empty cases\n");
      testLongestWord("", "");
      testLongestWord("!", "");
      testLongestWord(" ", "");
      testLongestWord("\t", "");
      testLongestWord("      ", "");
      testLongestWord("# $ ? % !", "");
  
      System.out.println("\nTesting edge cases\n");
      testLongestWord("a", "a");
      testLongestWord("abc", "abc");
      testLongestWord("abc d e f ghi", "abc");
      testLongestWord("a a b cc dd abc", "abc");
      testLongestWord("\"a a b cc dd abc.\"", "abc");
  
      System.out.println("\nTesting apostrophes and dashes\n");
      testLongestWord("this isn't five chars", "chars");
      testLongestWord("this should've been eight chars said the computer", "should've");
      testLongestWord("'this should've been eight chars', said the computer", "should've");
      testLongestWord("'hello world!', she said softly.", "softly");
      testLongestWord("topsy-turvy is a tenletter word", "topsy-turvy");
      testLongestWord("topsy-turvy should not be incorrectly eleven characters", "incorrectly");
      testLongestWord("---in-between-these---", "in-between-these");
      testLongestWord("---in---between---these---", "between");
      testLongestWord("here-is-an-edge-case but a muchmuchlongerword", "muchmuchlongerword");
      testLongestWord("d-o-n't-g-o-o-v-e-r-t-h-e-e-d-g-e with muchmuchlongerwords", "muchmuchlongerwords");
      testLongestWord("two=five-3 isn't three", "three");
  
      System.out.println("\nThese tests will be opposite in the C version\n");
      testLongestWord("the word antidisestablishmentarianism is very long but not as long as 'Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch'.", "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch");
      testLongestWord("the word antidisestablishmentarianism is very long but not as long as 'Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch'.", "antidisestablishment");
      testLongestWord("Java strings may contain \0 in the interior", "interior");
      testLongestWord("C strings cannot contain \0 in the interior", "strings");
  
      System.out.println("\nTotal number of tests executed: " + testsExecuted);
      System.out.println("Number of tests passed:         " + (testsExecuted - testsFailed));
      System.out.println("Number of tests failed:         " + testsFailed);
    }
  
    public static void testLongestWord(String line, String expected) 
    {
      String result = longestWord(line);
  
      if (result.equals(expected)) 
      {
        System.out.println("Passed: '" + result + "' from '" + line + "'");
      } 
      else 
      {
        System.out.println("FAILED: '" + result + "' instead of '" + expected + "' from '" + line + "'");
        testsFailed++;
      }
  
      testsExecuted++;
    }
  
    public static String longestWord(String line) 
    {
      int pos = 0;
      String longest = "";
      int longestLength = 0;
      String current = "";
      int currentLength = 0;
      char ch;
  
      line += ' ';
      while (pos &lt; line.length()) 
      {
        ch = line.charAt(pos);
  
        if ((ch == '\'' || ch == '-') &amp;&amp; pos &gt; 0 &amp;&amp; 
            Character.isLetter(line.charAt(pos - 1)) &amp;&amp; 
            Character.isLetter(line.charAt(pos + 1))) 
        {
  
          current += ch;
  
        } 
        else if (Character.isLetterOrDigit(ch)) 
        {
  
          current += ch;
          currentLength++;
  
        }
        else 
        {
  
          if (currentLength &gt; longestLength) 
          {
            longest = current;
            longestLength = currentLength;
          }
  
          current = "";
          currentLength = 0;
  
        }
  
        pos++;
      }
  
      return longest;
    }
  }
  </code></pre>
  
  <p>My C conversion that I'm working on:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;string.h&gt;
  
  static int testsExecuted = 0;
  static int testsFailed = 0;
  
  char testLongestWord(char line[], char expected[]);
  void longestWord(char line[]);
  
  int main(int args, char *argv[]){
      printf("%s\n", "Testing typical cases, including punctuation\n");
      testLongestWord("the quick brown foxes jumped over the lazy dogs", "jumped");
      testLongestWord("hello world she said", "hello");
      testLongestWord("Hello\tworld\tshe\tsaid", "Hello");
      testLongestWord("HELLO, world she said", "HELLO");
      testLongestWord("hello world! she said???", "hello");
      testLongestWord("\"hello world!\", she said.", "hello");
      testLongestWord("easy as abc123", "abc123");
      testLongestWord("easy as abc,123", "easy");
  
  
      printf("\n%s\n", "Testing empty cases\n" );
      testLongestWord("", "");
      testLongestWord("!", "");
      testLongestWord(" ", "");
      testLongestWord("\t", "");
      testLongestWord("      ", "");
      testLongestWord("# $ ? % !", "");
  
      printf("\n%s\n", "Testing edge cases\n" );
      testLongestWord("a", "a");
      testLongestWord("abc", "abc");
      testLongestWord("abc d e f ghi", "abc");
      testLongestWord("a a b cc dd abc", "abc");
      testLongestWord("\"a a b cc dd abc.\"", "abc");
  
  
      printf("\n%s\n", "Testing apostrophes and dashes\n" );
      testLongestWord("this isn't five chars", "chars");
      testLongestWord("this should've been eight chars said the computer", "should've");
      testLongestWord("'this should've been eight chars', said the computer", "should've");
      testLongestWord("'hello world!', she said softly.", "softly");
      testLongestWord("topsy-turvy is a tenletter word", "topsy-turvy");
      testLongestWord("topsy-turvy should not be incorrectly eleven characters", "incorrectly");
      testLongestWord("---in-between-these---", "in-between-these");
      testLongestWord("---in---between---these---", "between");
      testLongestWord("here-is-an-edge-case but a muchmuchlongerword", "muchmuchlongerword");
      testLongestWord("d-o-n't-g-o-o-v-e-r-t-h-e-e-d-g-e with muchmuchlongerwords", "muchmuchlongerwords");
      testLongestWord("two=five-3 isn't three", "three");
  
      printf("\n%s\n", "These tests will be opposite in the C version\n");
      testLongestWord("the word antidisestablishmentarianism is very long but not as long as 'Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch'.", "Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch");
      testLongestWord("the word antidisestablishmentarianism is very long but not as long as 'Llanfairpwllgwyngyllgogerychwyrndrobwyll-llantysiliogogogoch'.", "antidisestablishment");
      testLongestWord("Java strings may contain \0 in the interior", "interior");
      testLongestWord("C strings cannot contain \0 in the interior", "strings");
  
      printf("Total number of test executed:  %d\n", testsExecuted );
      printf("number of test passed:  %d\n", (testsExecuted - testsFailed));
      printf("Number of test failed: %d\n", testsFailed );
  
      //longestWord("Java strings may contain \0 in the interior");
  
  }
  
  char testLongestWord(char line[], char expected[]){
      char result[200];
  
      /*longestWord(line);*/
      strcpy(result, line);
      //char *result = longestWord(line);
      //printf("%s\n", line );
      //int ret = strcmp(result,expected);
  
      if(strcmp(result,expected)){ // function returns 0 if they are equal
          printf("passed: '%s' from '%s'\n", result, line);
      }else{
          printf("FAILED: '%s' from '%s'\n", expected, result);
          testsFailed++;
      }
      testsExecuted++;
      return 0;
  
  }
  
  
  void longestWord(char line[]){
      char longest[200];
  
      int pos = 0;
      int longestLength = 0;
      char current[300];
      int currentLength = 0;
      char ch;
      size_t maxPos = strlen(line);
  
      while(pos &lt; maxPos){
          ch = line[pos++];
          for(pos = 0; pos &lt; maxPos;pos++){
              ch = line[pos++];
              if((ch == '\'' || ch == '-') &amp;&amp; (pos &gt; 0) &amp;&amp; isalpha(line[pos-1]) &amp;&amp; isalpha(line[pos+1])){
                  strcpy(current, &amp;ch);
              }else if(isalpha(ch) || isdigit(ch)){
                  strcpy(current, &amp;ch);
                  currentLength++;
                  //printf("%s\n", longest );
  
              }else{
                  if(currentLength &gt; longestLength){
                      strcpy(longest,current);
                      longestLength = currentLength;
                  }
                  //strcpy(current, "");
                  currentLength =0;
              }
          }
  
      }
  
  }
  </code></pre>
  
  <p>The errors and warnings i'm getting EDIT: I'm no longer having these errors.</p>
  
  <p>I'm having problems with this line <code>String result = longestWord(line);</code> in java to c, the function longestWords is not transferring the result to result. Is there a way to do it?</p>