Ok heres my problem the code is working fine but i cant read extended ascii characters i got a tip that the problem is that extended ascii characters are 16 bits not like the original 8bits per character i dont know where to start can you gets give me tips on how to do this im programming in linux by the way.

heres the example of the text file i cant read in this program
Azərbaycan Respublikasının Prezidenti İlham Əliyev iyunun 1-də Romada onun üçün ayrılmış iqamətgahda Moldova Respublikası Prezidentinin vəzifəsini icra edən Marian Lupu ilə görüşmüşdür.

Görüşdə Azərbaycan ilə Moldova arasında ikitərəfli münasibətlərin uğurlu inkişafından məmnunluq ifadə olundu, ölkələrimizin beynəlxalq təşkilatlarda bir-birinin mövqeyini dəstəkləməsinin önəmi qeyd edildi, əlaqələrimizin daha da genişləndirilməsi üçün yaxşı potensialın olduğu vurğulanaraq bu potensialın reallaşdırılması ilə bağlı fikir mübadiləsi aparıldı.

#include<stdio.h>
#include<string.h>
#include<stdlib.h>


int ascConverter(char ch)
{
	int ascVal;
	ascVal = toascii(ch);
	return ascVal;
}
void binaryConverter(int num,FILE **myFp)
{
	int rem, i = 1, counter = 7;
   	int bin = 0;
	char buffer[20];

	
	   while(num > 0){
      		rem = num % 2;
      		num = num / 2;
      		bin = bin + (i*rem);
      		i = i * 10;
		counter--;
   	   }
	sprintf(buffer, "%d", bin);
	while(counter != 0){
		fprintf(*myFp,"0");
		counter--;
	}
	fprintf(*myFp,"%s",buffer);	
}
int decimalConverter(int num)
{
	int bnum, dec = 0, base = 1, rem ;

	bnum = num;

	while( num > 0){
		rem = num % 10;
		dec = dec + rem * base;
		num = num / 10 ;
		base = base * 2;
	}
	return dec;
}

int main(int argc, char *argv[])
{
	int i;
   	char convert;
   	char buf[255] = { };
   
	if(argc == 4){
		FILE *type;
   		FILE *fb;
		type = fopen(argv[2],"r");
   		fb = fopen(argv[3],"w+");
		if(strcmp(argv[1],"encode") == 0){	
   			while(fgets(buf, sizeof(buf), type) != NULL){	
				for(i = 0;  i < sizeof(buf);i++){
					convert = buf[i];
					printf("%c",buf[1]);
					int conv = ascConverter(convert);
					if(conv > 0){
						binaryConverter(conv, &fb);
					}
				}
				memset (buf, '\0', sizeof(buf));
			}
		}
		else if(strcmp(argv[1],"decode") == 0){
			char decodeBuf[50];
   			int toInt, toDecimal;
   			uint8_t toChar; 
				while(fgets(decodeBuf, 8, type) != NULL){
					toInt = atoi(decodeBuf);
					toDecimal = decimalConverter(toInt);
					toChar = (char)toDecimal;
					fprintf(fb,"%c",toChar);
    				}
		}   
		else{
			printf("Enter either encode/decode in the 1st argument\n");
   		}
		fclose(fb);
		fclose(type);
	}
	else{
		printf("Enter 3 arguments:\n");
		printf("The 1st argument that you shall type is either encoder/decode\n");
		printf("The 2nd argument is the name of the file that you will encode or decode\n");
		printf("The 3rd argument is where the encoded or decoded file will be written\n");
	}
	return 0;
}
WaltP commented: Sentences, dammit! Sentences!!! -4

Extended ascii characters are 8 bits, see link below

http://telecom.tbi.net/asc-ibm.html

Try reading your characters into an unsigned char variable.

line 12: you don't need double star on FILE since the function is not attempting to change the caller's pointer. Just pass FILE pointer by value -- with only one star then on line 66 remove the & operator.

line 61: you are assuming that fgets() read in exactly sizeof(buf) number of bytes. Most likely it did not. The loop on line 61 needs to check for end-of-string null terminator instead of sizeof(buf).

i think the problem is imba using linux so characters extended ascii characters are 16 bits i need tips on where will i start im kinda lost right now on what to do

i think the problem is imba using linux so characters extended ascii characters are 16 bits i need tips on where will i start im kinda lost right now on what to do

Are you referring to wide characters or extended ascii characters?

example this characters öüş from what i found out that this characters are 16 bit int linux i need to make it 8bits so i can print it im not sure if im right its just 1 tip that i got from a friend

Quick question ... Is you problem that you cannot read a 16 bit character or is the problem that you cannot use the toAscii function on a 16 bit character ?

I think you might find this link useful to read in 16 bit characters ....

I do not think you can use ASCII for characters from a foreign language .... You will have to use Unicode for that

i cant read multibyte characters from a text file is the problem im having

Did you go through the link that I posted ?

yes ive read the link but im not sure on how to use it for my problem

In the example text that you posted are all chars 16 bit ?

Also is it necessary to convert it to ASCII or can you convert it to unicode ? This link explains how to read unicode chars from a text file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.