NO

Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
General discussions / Re: escape sequence in a string
« Last post by jamiebreeze on October 06, 2019, 05:21:46 pm »
Thank you to John and TimoVJL, but the problem still exists.
My system language is Chinese, but for 'codepage', I dont know?
I've tried several hex values to figure out why, and no matter which value I used, once it's big enough, it will be '3f'.
I'm going to test my orignal code on another computer to confirm the version problem (oh yes mine is Pelles C 9.00.9 installed on a Win10-64bit system).
Thank you again Timo for trying my codes on your machine.
22
General discussions / Re: escape sequence in a string
« Last post by TimoVJL on October 04, 2019, 10:50:27 am »
what Pelles C version, 9 ?
as 3fh is '?', what is your language/ codepage ?

for me it works.
Code: [Select]
unsigned char *p = (unsigned char *)"\xA0\xFF";give us a zipped project or just an object file, if it still fails.

optimized version don't even create string, just put parameters
Code: [Select]
_main:
  [00000000] 68FF000000             push              FF
  [00000005] 68A0000000             push              A0
  [0000000A] 6800000000             push              @9
  [0000000F] E800000000             call              _printf
EDIT:
using ntleas
Code: [Select]
Building test_ch.obj.
C:\code\PellesC\_Forum\test_ch.c(6): warning #2223: Unable to convert character '\u00a0' to codepage 932; using default character.
C:\code\PellesC\_Forum\test_ch.c(6): warning #2223: Unable to convert character '\u00ff' to codepage 932; using default character.
Done.
Code: [Select]
_main:
  [00000000] 6A3F                   push              3F
  [00000002] 6A3F                   push              3F
  [00000004] 6800000000             push              @11
  [00000009] E800000000             call              _printf
  [0000000E] 83C40C                 add               esp,C
  [00000011] 31C0                   xor               eax,eax
  [00000013] C3                     ret               

another way to do byte array
Code: [Select]
unsigned char s[] = {0xA0,0xFF,0};
test ntleas.exe with test_ch.c
A is App parameters
Code: [Select]
x64\ntleas.exe pocc.exe Atest_ch.c
23
General discussions / Re: escape sequence in a string
« Last post by John S. Kent on October 04, 2019, 01:32:25 am »
You are trying to put 2 characters in a single character.  Assuming ASCII encoding, 0xA0 has a character with no glyph. 0xFF has the glyph that has 2 dots over a 'ΓΏ'. The display value 0x3f has the glyph '?'.

My guess is that compiler is trying to tell you that it can't display what you are asking for.

All this has to do with language localization & character sets being used.  You need to read about the c Standard closely for how c handles language encoding differences. Actually a complex subject.

This is my 1st posting on the form. I hope this is helpful; otherwise my apologies.
24
General discussions / Re: escape sequence in a string
« Last post by jamiebreeze on October 03, 2019, 04:56:33 pm »
I supposed the result would be "a0, ff", but "3f, 3f" is what i get, seems abnormal?
25
General discussions / Re: escape sequence in a string
« Last post by bitcoin on October 03, 2019, 01:32:32 pm »
What do you want?
26
General discussions / escape sequence in a string
« Last post by jamiebreeze on October 02, 2019, 10:10:25 am »
Can anyone help me about the following code? The result i got is wierd
Code: [Select]
#include <stdio.h>

int main(int argc, char *argv[])
{
unsigned char *p;
p = "\xA0\xFF";
printf("%x, %x\n", *p, *(p+1));

    return 0;
}

27
Beginner questions / Re: How to delete some Content in a File ?
« Last post by John1 on September 29, 2019, 08:18:31 pm »
Hello TimoVJL,

Thanks a lot, it works now. It compile and execute well, just I have a problem that it do not delete as expected. Something is messed up, maybe from the adding function. I will play with it around, and perhaps open another post.

And thank you, I will try to learn, how to debug through Pelles C, or maybe also using some other Debugger (e.g. GDB or WinDbg) .

Kind Regards
John1

p.s my adding function :

Code: [Select]
void addNewElement(void) {
 printf("Data :  ");
 if(fgets(carV, BUF, stdin) == NULL) {
  fprintf(stderr, "Wrong Input\n");
  return;
 }
 killNL(carV);

 FILE *fp = fopen(DATAFILE, "ab");

 if(fp == NULL) {
  printf("Error in open: %s\n", DATAFILE);
  exit(EXIT_FAILURE);
 }
 if(fwrite(&carV, sizeof(carV), 1, fp) != 1) {
  fprintf(stderr, "Error in write, in %s\n", DATAFILE);
  fclose(fp);
  return;
 }
 fclose(fp);
}

//killNL
void killNL(char *str) {
 size_t p = strlen(str);
 if(str[p-1] == '\n') {
  str[p-1] = '\0';
 }
}

28
Beginner questions / Re: How to delete some Content in a File ?
« Last post by TimoVJL on September 29, 2019, 02:59:48 pm »
use debugger to learn how code works.
Code: [Select]
  int keylen = strlen(val); // keyword length with LF
  val[--keylen] = 0; // remove LF and fix keylen
29
Beginner questions / Re: How to delete some Content in a File ?
« Last post by John1 on September 28, 2019, 09:03:05 pm »
Hello TimoVJL,

Thanks for the explanation, now I can understand it a bit better.

Sorry for annoying you, but I added your corrections, and now it can't execute.
I think because of the last fwrite(p1, (pbuf + len) - p1, 1, fp);  , throws an exception, as I could more or less find out with debugging.

CRT: unhandled exception (main) -- terminating
*** Process returned 255 ***


Kind regards
John1

Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define file "test_str_del.txt"

int main(void) {
  FILE *fp;
  char val[256];
  val[strcspn(val, "\r\n")] = 0;  // does remove the carriage return and newline ?
  if(fgets(val,sizeof(val),stdin) == NULL) {
   printf("Wrong Input\n");     
  } 
  fp = fopen(file, "rb");
  int keylen = strlen(val);

  if (fp) {
   fseek(fp, 0, SEEK_END);
   int len = ftell(fp);
   fseek(fp, 0, SEEK_SET);
   char *pbuf = malloc(len+1);

   if (pbuf) {
    fread(pbuf, len, 1, fp);
    fclose(fp);
    fp = NULL;
    char *p1 = pbuf, *p = pbuf;

    while (p = strstr(p, val)) {
     if (!fp){ fp = fopen(file, "wb");}
      fwrite(p1, p - p1, 1, fp);
      p += keylen;
      p1 = p;
     }
     if (p1) { // write rest of text
      fwrite(p1, (pbuf + len) - p1, 1, fp); // doesn't execute
      printf("file almost finished");
     }
    }
    fclose(fp);
   }
  return 0;
}

30
Beginner questions / Re: How to delete some Content in a File ?
« Last post by TimoVJL on September 27, 2019, 12:22:03 am »
1. fgets read a LF to buffer, so remove it
2. use binary format to avoid translations
3. write remainder buffer if needed
Pages: 1 2 [3] 4 5 ... 10