Diff
checker
텍스트
텍스트
이미지
문서
Excel
폴더
Legal
Enterprise
데스크톱
요금제
로그인
데스크톱 앱 다운로드
텍스트 비교
두 텍스트 파일의 차이점을 찾아보세요
도구
기록
실시간 편집
공백 변경 숨기기
변경 없는 행 숨기기
줄바꿈 비활성화
레이아웃
나란히 보기
합쳐 보기
비교 단위
스마트
단어
글자
텍스트 스타일
모양 변경
구문 강조
언어 선택
제외
텍스트 변환
첫 변경으로
수정
Diffchecker Desktop
가장 안전하게 Diffchecker를 사용하는 방법. 데스크톱 앱을 사용하면 비교 데이터가 외부로 전송되지 않습니다!
데스크톱 앱 받기
Untitled diff
생성일
11년 전
비교 결과 만료 없음
초기화
내보내기
공유
설명
14 삭제
행
총
삭제
글자
총
삭제
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
156 행
복사
0 추가
행
총
추가
글자
총
추가
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
147 행
복사
#include <stdbool.h>
#include <stdbool.h>
#include <ctype.h>
#include <ctype.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <strings.h>
#include <strings.h>
#include "dictionary.h"
#include "dictionary.h"
unsigned int wordCount = 0;
unsigned int wordCount = 0;
//Define the size of hash table
//Define the size of hash table
#define SIZE 26
#define SIZE 26
//Create linked list
//Create linked list
typedef struct node
typedef struct node
{
{
char word[LENGTH + 1];
char word[LENGTH + 1];
struct node* next;
struct node* next;
}
}
node;
node;
//Create hashtable and set its index to NULL
//Create hashtable and set its index to NULL
node* hashtable[SIZE] = {NULL};
node* hashtable[SIZE] = {NULL};
//Make a hash function
//Make a hash function
int hashFunction(const char letter)
int hashFunction(const char letter)
{
{
return letter - 'a';
return letter - 'a';
}
}
/**
/**
* Returns true if word is in dictionary else false.
* Returns true if word is in dictionary else false.
*/
*/
bool check(const char* word)
bool check(const char* word)
{
{
// TODO
// TODO
// converting the word to lower letters
// converting the word to lower letters
char lowerLetterWord[LENGTH + 1];
char lowerLetterWord[LENGTH + 1];
for (int i = 0, n = strlen(word); i < n; i++)
for (int i = 0, n = strlen(word); i < n; i++)
{
{
lowerLetterWord[i] = tolower(word[i]);
lowerLetterWord[i] = tolower(word[i]);
}
}
lowerLetterWord[strlen(word)] = '\0';
lowerLetterWord[strlen(word)] = '\0';
int ind = hashFunction(lowerLetterWord[0]);
int ind = hashFunction(lowerLetterWord[0]);
// checking through the hashtable
// checking through the hashtable
if (hashtable[ind] == NULL)
if (hashtable[ind] == NULL)
{
{
return false;
return false;
}
}
else
else
{
{
복사
복사됨
복사
복사됨
node *tableindex =
malloc(sizeof(node));
node *tableindex =
hashtable[ind];
tableindex =
hashtable[ind];
do
do
{
{
if (strcmp(lowerLetterWord, tableindex->word) == 0)
if (strcmp(lowerLetterWord, tableindex->word) == 0)
{
{
return true;
return true;
}
}
else
else
{
{
tableindex = tableindex->next;
tableindex = tableindex->next;
}
}
} while (tableindex->next != NULL);
} while (tableindex->next != NULL);
//checking the last node too
//checking the last node too
if (strcmp(lowerLetterWord, tableindex->word) == 0)
if (strcmp(lowerLetterWord, tableindex->word) == 0)
{
{
return true;
return true;
}
}
복사
복사됨
복사
복사됨
free(tableindex);
}
}
return false;
return false;
}
}
/**
/**
* Loads dictionary into memory. Returns true if successful else false.
* Loads dictionary into memory. Returns true if successful else false.
*/
*/
bool load(const char* dictionary)
bool load(const char* dictionary)
{
{
// TODO
// TODO
// opening the file
// opening the file
FILE *fp = fopen(dictionary,"r");
FILE *fp = fopen(dictionary,"r");
// checking if the file is valid
// checking if the file is valid
if (fp == NULL)
if (fp == NULL)
{
{
printf("Couldn`t open the dictionary file\n");
printf("Couldn`t open the dictionary file\n");
return false;
return false;
}
}
char word[LENGTH + 1];
char word[LENGTH + 1];
while (fscanf(fp, "%s", word) == 1)
while (fscanf(fp, "%s", word) == 1)
{
{
node *newWordNode = malloc(sizeof(node));
node *newWordNode = malloc(sizeof(node));
strcpy(newWordNode->word, word);
strcpy(newWordNode->word, word);
newWordNode->next = NULL;
newWordNode->next = NULL;
int hash = hashFunction(word[0]); //finding the index of the word
int hash = hashFunction(word[0]); //finding the index of the word
복사
복사됨
복사
복사됨
if (hashtable[hash] == 0x0)
{
hashtable[hash] = newWordNode;
wordCount++;
복사
복사됨
복사
복사됨
}
newWordNode->next = hashtable[hash];
else
hashtable[hash] = newWordNode;
{
wordCount++;
newWordNode->next = hashtable[hash];
hashtable[hash] = newWordNode;
wordCount++;
}
}
}
fclose(fp);
fclose(fp);
return true;
return true;
}
}
/**
/**
* Returns number of words in dictionary if loaded else 0 if not yet loaded.
* Returns number of words in dictionary if loaded else 0 if not yet loaded.
*/
*/
unsigned int size(void)
unsigned int size(void)
{
{
//Return the size of the dictionary that has been loaded
//Return the size of the dictionary that has been loaded
return wordCount;
return wordCount;
}
}
/**
/**
* Unloads dictionary from memory. Returns true if successful else false.
* Unloads dictionary from memory. Returns true if successful else false.
*/
*/
bool unload(void)
bool unload(void)
{
{
//Declare a variable to hold the first index of the hash table
//Declare a variable to hold the first index of the hash table
int index = 0;
int index = 0;
while(index < SIZE)
while(index < SIZE)
{
{
node* cursor = hashtable[index];
node* cursor = hashtable[index];
//While the end of the list is yet to be reached free the nodes from memory
//While the end of the list is yet to be reached free the nodes from memory
while(cursor != NULL)
while(cursor != NULL)
{
{
node* temp = cursor;
node* temp = cursor;
cursor = cursor->next;
cursor = cursor->next;
free(temp);
free(temp);
}
}
index++;
index++;
}
}
return true;
return true;
}
}
저장된 비교 결과
원본
파일 열기
#include <stdbool.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include "dictionary.h" unsigned int wordCount = 0; //Define the size of hash table #define SIZE 26 //Create linked list typedef struct node { char word[LENGTH + 1]; struct node* next; } node; //Create hashtable and set its index to NULL node* hashtable[SIZE] = {NULL}; //Make a hash function int hashFunction(const char letter) { return letter - 'a'; } /** * Returns true if word is in dictionary else false. */ bool check(const char* word) { // TODO // converting the word to lower letters char lowerLetterWord[LENGTH + 1]; for (int i = 0, n = strlen(word); i < n; i++) { lowerLetterWord[i] = tolower(word[i]); } lowerLetterWord[strlen(word)] = '\0'; int ind = hashFunction(lowerLetterWord[0]); // checking through the hashtable if (hashtable[ind] == NULL) { return false; } else { node *tableindex = malloc(sizeof(node)); tableindex = hashtable[ind]; do { if (strcmp(lowerLetterWord, tableindex->word) == 0) { return true; } else { tableindex = tableindex->next; } } while (tableindex->next != NULL); //checking the last node too if (strcmp(lowerLetterWord, tableindex->word) == 0) { return true; } free(tableindex); } return false; } /** * Loads dictionary into memory. Returns true if successful else false. */ bool load(const char* dictionary) { // TODO // opening the file FILE *fp = fopen(dictionary,"r"); // checking if the file is valid if (fp == NULL) { printf("Couldn`t open the dictionary file\n"); return false; } char word[LENGTH + 1]; while (fscanf(fp, "%s", word) == 1) { node *newWordNode = malloc(sizeof(node)); strcpy(newWordNode->word, word); newWordNode->next = NULL; int hash = hashFunction(word[0]); //finding the index of the word if (hashtable[hash] == 0x0) { hashtable[hash] = newWordNode; wordCount++; } else { newWordNode->next = hashtable[hash]; hashtable[hash] = newWordNode; wordCount++; } } fclose(fp); return true; } /** * Returns number of words in dictionary if loaded else 0 if not yet loaded. */ unsigned int size(void) { //Return the size of the dictionary that has been loaded return wordCount; } /** * Unloads dictionary from memory. Returns true if successful else false. */ bool unload(void) { //Declare a variable to hold the first index of the hash table int index = 0; while(index < SIZE) { node* cursor = hashtable[index]; //While the end of the list is yet to be reached free the nodes from memory while(cursor != NULL) { node* temp = cursor; cursor = cursor->next; free(temp); } index++; } return true; }
수정본
파일 열기
#include <stdbool.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include "dictionary.h" unsigned int wordCount = 0; //Define the size of hash table #define SIZE 26 //Create linked list typedef struct node { char word[LENGTH + 1]; struct node* next; } node; //Create hashtable and set its index to NULL node* hashtable[SIZE] = {NULL}; //Make a hash function int hashFunction(const char letter) { return letter - 'a'; } /** * Returns true if word is in dictionary else false. */ bool check(const char* word) { // TODO // converting the word to lower letters char lowerLetterWord[LENGTH + 1]; for (int i = 0, n = strlen(word); i < n; i++) { lowerLetterWord[i] = tolower(word[i]); } lowerLetterWord[strlen(word)] = '\0'; int ind = hashFunction(lowerLetterWord[0]); // checking through the hashtable if (hashtable[ind] == NULL) { return false; } else { node *tableindex = hashtable[ind]; do { if (strcmp(lowerLetterWord, tableindex->word) == 0) { return true; } else { tableindex = tableindex->next; } } while (tableindex->next != NULL); //checking the last node too if (strcmp(lowerLetterWord, tableindex->word) == 0) { return true; } } return false; } /** * Loads dictionary into memory. Returns true if successful else false. */ bool load(const char* dictionary) { // TODO // opening the file FILE *fp = fopen(dictionary,"r"); // checking if the file is valid if (fp == NULL) { printf("Couldn`t open the dictionary file\n"); return false; } char word[LENGTH + 1]; while (fscanf(fp, "%s", word) == 1) { node *newWordNode = malloc(sizeof(node)); strcpy(newWordNode->word, word); newWordNode->next = NULL; int hash = hashFunction(word[0]); //finding the index of the word newWordNode->next = hashtable[hash]; hashtable[hash] = newWordNode; wordCount++; } fclose(fp); return true; } /** * Returns number of words in dictionary if loaded else 0 if not yet loaded. */ unsigned int size(void) { //Return the size of the dictionary that has been loaded return wordCount; } /** * Unloads dictionary from memory. Returns true if successful else false. */ bool unload(void) { //Declare a variable to hold the first index of the hash table int index = 0; while(index < SIZE) { node* cursor = hashtable[index]; //While the end of the list is yet to be reached free the nodes from memory while(cursor != NULL) { node* temp = cursor; cursor = cursor->next; free(temp); } index++; } return true; }
비교하기