Home > Blockchain >  incrementing a buffer array address not changing the start address of array as shown in printf
incrementing a buffer array address not changing the start address of array as shown in printf

Time:10-14

so I have an array that I want to skip few characters so I can print when after the first few characters in array this is my code

  char in_buffer[8000]={0};
  memcpy(in_buffer,REQUEST_1,8000);
  *(in_buffer 3);
  printf("%s\n",in_buffer);

in this line I am skipping 3 characters in the start (adrress 3) then do printf("%s\n",in_buffer);

but I am getting printf from the start of buffer

GET / HTTP/1.1
Host: localhost:5000
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0
Accept: text/html,application/xhtml xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: none
Sec-Fetch-User: ?1

in above output characters in start GET should not print. how can I do this like skipping few charaters with incrementing array address with indirection operator

Update

I have this function

void print(char *array)
{
  printf("%s\n",array);
  if(strncmp(array,"\r\n\r\n",4)!=0)
  print(array 1);
  else{return;}
}

array contains

#define REQUEST_1 "GET / HTTP/1.1\r\n" \
"Host: localhost:5000\r\n" \
"User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:93.0) Gecko/20100101 Firefox/93.0\r\n" \
"Accept: text/html,application/xhtml xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8\r\n" \
"Accept-Language: en-US,en;q=0.5\r\n" \
"Accept-Encoding: gzip, deflate\r\n" \
"Connection: keep-alive\r\n" \
"Upgrade-Insecure-Requests: 1\r\n" \
"Sec-Fetch-Dest: document\r\n" \
"Sec-Fetch-Mode: navigate\r\n" \
"Sec-Fetch-Site: none\r\n" \
"Sec-Fetch-User: ?1\r\n\r\n\0" \

it does the same thing to increment the address but it gives segFault so actually what I am doing is I recursively call print function with advancing address and check if \r\n\r\n found then if found just return. But its not working what I am doing wrong?

CodePudding user response:

This:

*(in_buffer 3);  // Expression result unused
printf("%s\n",in_buffer);

should be:

printf("%s\n",in_buffer   3);
  •  Tags:  
  • c
  • Related