static int		store_in_list(t_disp **root, Elf64_Sym *symbol,
				      char *symbol_name)
{
  t_disp		*tmp;
  t_disp		*clist;
  t_disp		*elem;

  clist = *root;
  tmp = NULL;
  if (!(elem = malloc(sizeof(*elem))))
    {
      printf("syscall 'malloc' failed, abort\n");
      return (-1);
    }
  elem->symbol = symbol;
  elem->symbol_name = symbol_name;
  elem->next = NULL;
  while (clist != NULL && custom_strcmp(clist->symbol_name, symbol_name) <= 0)
    {
      tmp = clist;
      clist = clist->next;
    }
  elem->next = clist;
  if (tmp != NULL)
    tmp->next = elem;
  else
    *root = elem;
  return (0);
}
예제 #2
0
int main()
{
  char *n;
  printf("...Programma avviato: 'quit' per terminare.\n");
  do
    {
      printf("------> %s\n",n);
    }
  while(scanf("%s", n) != EOF && !custom_strcmp(n,"quit"));
  // 1) While does not accept ','. To concatenate 2 or more conditions you must use a boolean operator such as "&&" "||" (and,or).
  // 2) Scanf returns the number of scanned and assigned values OR returns the EOF sequence (end of line).
  // 3) In order to compare strings is a good practice to include <string.h> and use the strcmp(char*,char*) function
  // 4) Using scanf for this kind of operations (and scanf in general) as you know it's not very recommended.
  // 4...) Use fgets() instead.

  printf("...Programma terminato.\n");
  return 0;
}
예제 #3
0
void GetDefinition(LPTSTR Word, int len)
{
    if (len>0)
    {
        TCHAR* FileName = new TCHAR[10];
        wsprintf(FileName, T(Dic\\%c.txt\0), Word[0]);

        char* c_str = new char[len + 1];
        for (int i = 0; i < len; ++i)
            c_str[i] = Word[i];
        c_str[len] = 0;

        HANDLE hDic = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
        if (hDic == INVALID_HANDLE_VALUE)
            return;
        HANDLE hFMap = CreateFileMapping(hDic, NULL, PAGE_READONLY, NULL, NULL, NULL);
        if (hFMap == INVALID_HANDLE_VALUE)
        {
            CloseHandle(hDic);
            return;
        }
        char* pMap = (char*)MapViewOfFile(hFMap, FILE_MAP_READ, 0, 0, NULL);

        LARGE_INTEGER a;
        GetFileSizeEx(hDic, &a);

        int begin = 0;
        int end = a.QuadPart;
        int mid;

        bool failed = false;

        while (begin < end)
        {
            mid = (begin + end) / 2;
            while (pMap[mid] != '\n') --mid;
            while (!isalpha(pMap[mid]))
                ++mid; //now mid is at start of some word.
            if (custom_strcmp(c_str, pMap + mid) < 0)
            {
                if (end == mid)
                {
                    failed = true;
                    break;
                }
                end = mid;
            }
            else if (custom_strcmp(c_str, pMap + mid) > 0)
            {
                if (begin == mid)
                {
                    failed = true;
                    break;
                }
                begin = mid;
            }
            else break;
        }
        end = mid;
        while (pMap[end] != '\n') ++end;

        if (!failed)
        {
            TCHAR* DefText = new TCHAR[end - mid + 1]();
            for (int i = mid; i < end; ++i)
                DefText[i - mid] = pMap[i];

            SetWindowText(hReport, DefText);
            delete[] DefText;
        }
        else
        {
            SetWindowText(hReport, T(Failed to load definition.));
        }

        UnmapViewOfFile(pMap);
        CloseHandle(hFMap);
        CloseHandle(hDic);
    }