#include<stdlib.h>
#include<stdio.h>
#include<string.h>
//This program is a sorting application that reads a sequence of numbers
//from a file and prints them on the screen . The reading from the file here,
//is a call back function .
typedef int (*CompFunc)(const char* , const char*);
typedef int (*ReadCheck)(char nullcheck);
char array[100];
//Let this function be done in the library itself . It doesn't care as to
//where the compare function and how is it implemented . Meaning suppose
//the function wants to do sort in ascending order or in descending order
//then the changes have to be done by the client code in the "COMPARE" function
//who will be implementing the lib code .
void ReadFile(FILE *fp,ReadCheck rc)
{
char a;
char d[100];
int count = 0,count1=0;
a=fgetc(fp);
while(1 != (*rc)(a))
{ if(a=='\0')
{
//d[count1]='\0';
strcpy(&array[count],d);
count=count+1;
}
else
{
d[count1]=a;
count1=count1+1;
}
}
}
void Bubblesort(char* array , int size , int elem_size , CompFunc cf)
{ int i,j;
int *temp;
for(i=0;i < size ;i++)
{
for (j=0;j < size -1 ; j++)
{
// make the callback to the comparision function
if(1 == (*cf)(array+j*elem_size,array+ (j+1)*elem_size))
{
//interchanging of elements
temp = malloc(sizeof(int *) * elem_size);
memcpy(temp , array+j*elem_size,elem_size);
memcpy(array+j*elem_size,array+(j+1)*elem_size,elem_size);
memcpy(array + (j+1)*elem_size , temp , elem_size);
free(temp);
}
}
}
}
//Let these functions be done at the client side
int Compare(const char* el1 , const char* el2)
{
int element1 = *(int*)el1;
int element2 = *(int*)el2;
if(element1 < element2)
return -1;
if(element1 > element2)
return 1 ;
return 0;
}
int ReadChecked(char nullcheck)
{
if (nullcheck=='\n')
return 1;
else
return 0;
}
int main()
{
FILE *fp1;
int k;
fp1=fopen("readdata.txt","r");
ReadFile(fp1,&ReadChecked);
Bubblesort((char*)array,5,sizeof(array[0]),&Compare);
printf("after sorting \n");
for (k=0;k<5;k++)
printf("%d",array[k]);
return 0;
}
-1
A
답변
1
1
while(1 != (*rc)(a))
관련 문제
- 1. 잠시 후 IIS가 중지되는 이유는 무엇입니까?
- 2. Android : 간헐적으로 일시 중지되는 스레드
- 3. jQuery의 일부 행에서 Chrome이 일시 중지되는 이유는 무엇입니까?
- 4. 이 CAKeyFrameAnimation이 불투명도가 0으로 중지되는 이유는 무엇입니까?
- 5. Internet Explorer 8에서 사이트로드가 일시 중지되는 원인은 무엇입니까?
- 6. 이 C 코드가 컴파일되는 이유는 무엇입니까?
- 7. 이 C++ 코드가 작동하지 않는 이유는 무엇입니까?
- 8. 이 C# 코드가 오류를 일으키는 이유는 무엇입니까?
- 9. 이 코드가 작동하지 않는 이유는 무엇입니까? C++
- 10. 해제 한 후 nil로 설정하는 이유는 무엇입니까?
- 11. 이 코드가 위에서 언급 한 장소에서 멈추는 이유는 무엇입니까?
- 12. grep을 수행 한 후 vim으로 전달한 후 종료하는 이유는 무엇입니까?이 이상한 콘솔이 오작동하는 이유는 무엇입니까?
- 13. "폭발 한"파이썬 코드가 실제로 더 빨리 실행되는 이유는 무엇입니까?
- 14. 스레드를 일시 중지/일시 중지 한 다음 계속하는 방법은 무엇입니까?
- 15. 사용량이 많은 LAMP 서버에서 파일 업로드가 중지되는 이유는 무엇입니까?
- 16. 이 코드가 충돌하는 이유는 무엇입니까?
- 17. 조치 코드가 실행 된 후 내 ActionFilterAttribute가 리디렉션되는 이유는 무엇입니까?
- 18. select 문의 중에 일부 행이 반환 된 후 SQL Server가 중지되는 이유는 무엇입니까?
- 19. 호스트를 전환 한 후 $ _SESSION이 작동하지 않는 이유는 무엇입니까?
- 20. IronPython 코드가 실패하는 이유는 무엇입니까?
- 21. 코드가 작동하지 않는 이유는 무엇입니까?
- 22. 잠시 동안 실행 한 후 AJAX 요청이 중단되는 이유는 무엇입니까?
- 23. 이유는/나는 다음과 같은 코드가 C
- 24. 디버깅을 중지 한 후 Visual Studio가 계속 빌드되는 이유는 무엇입니까?
- 25. 내 코드가 무기한으로 매달려있는 이유는 무엇입니까?
- 26. C#이 코드가 GUI를 제대로 표시하지 않는 이유는 무엇입니까?
- 27. 내 코드가 Form2Thread.Join()에 멈추는 이유는 무엇입니까?
- 28. ReSharper가 form.Show() 코드가 작동하지 않는 이유는 무엇입니까?
- 29. Windows installer에서 설치 한 후 app.config가 추가되지 않는 이유는 무엇입니까?
- 30. Javascript JQuery에서 아약스 콘텐츠를로드 한 후 루핑 및 일시 중지
무엇이 문제입니까? –
디버거를 사용하여 멈추는 부분을 보았습니까? – Cascabel