Code:
#include <stdio.h>
#include <conio.h>
void swap (int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
int sort(int a[], int x)
{
int i, j;
for (i = -1; i < x-1; i++)
{
for(j=i; j >= 0; j--)
{
printf(" if %d > %d \n",a[j], a[j+1]);
if (a[j] > a[j+1])
{
printf("\n\nthen swap them\n");
swap(&a[j], &a[j+1]);
}
}
}
}
int main()
{
int a[100], x, i;
printf(" Spots in array: \n ");
scanf("%d",&x);
for( i=0;i<x;i++)
{
printf("\n\n Spot %d in array : ",i+1);
scanf("%d",&a[i]);
}
sort(a ,x);
printf("\n\n\n\n\n iSort \n\n");
for( i=0;i<x;i++)
{
printf("%d at %d\n",a[i], &a[i]);
}
FILE *fp;
fp=fopen("c:\\test.txt", "wb");
fwrite(a, sizeof(a[0]), sizeof(a)/sizeof(a[0]), fp);
system("Pause");
}
I am now trying to send my array into a file on C:
Using fwrite in this manner should write from memory into the file according the the I/O tutorial.
this however is my output:
Code:
h I H % ˆ P P s P › › › › Øþ( Õq)w þÿÿÿ î<%w I H p % î<%w P ` h ˆ ð ¼ý( Ä } øþ( Õq)wÎ1þÿÿÿš8%w’4%w h h ` ÿ( ͘Óu Ú˜Óu÷•õ ÿ^n€þÿÿÿùÓuC®ÓuÐþ( Äÿ( ÕŒÕuhn€þÿÿÿÚ˜Óuú Ôuh x 8ÿ( ŸÔu pÿ( ä Ü @-} 7