C -> sizeof string ist immer 8

#include "usefunc.h" //don't worry about this -> lib I wrote
int main()
{
  int i;
  string given[4000], longest = "a"; //declared new typdef. equivalent to 2D char array
  given[0] = "a";
  printf("Please enter words separated by RETs...\n");
  for (i = 1; i < 4000 && !StringEqual(given[i-1], "end"); i++)
    {
      given[i] = GetLine();
      /*
      if (sizeof(given[i]) > sizeof(longest))
    {
      longest = given[i];
    }
      */
      printf("%lu\n", sizeof(given[i])); //this ALWAYS RETURNS EIGHT!!!
    }
  printf("%s", longest);
}

Warum kommt es immer wieder 8???

  • Wenn string ein typedef für char*?
  • typedef, entschuldigen Sie mich. C
  • Was ist string?
  • Sie haben andere Probleme hier. Der code fehlerhaft ist, mit einem unsyntactic for-Anweisung und eine unübertroffene */, und es ist nicht klar, was ich in deinem printf-Anweisung.
  • was ist das...es hat nicht richtig einfügen
  • sizeof zurück size_t welche ausgedruckt werden muss mit %zu, nicht %lu

InformationsquelleAutor tekknolagi | 2011-02-09
Schreibe einen Kommentar