Sunday, October 26, 2014

Copying non null-terminated char array to String

Sometimes while listening to data on a network, the packet structure defined contains data members of type char[]. In most of the cases, the data in these char[] data members  will not be null terminated.

i.e.


structObj.charArray[8] = { 'p', 'a', 'r', 'a', 'g', ' ', ' ', ' ' };  
//see all 8 chars occupied, with no null termination at the end. 

 How do you read the object in your program. There are various ways, here's one:

#include <iostream>
#include <string>
#include <cassert>

#define ARRAY_SIZE(a) sizeof(a)/sizeof(a[0])
#define MAX_INPUT_ARR_SIZE 5
int main()
{
    char input[MAX_INPUT_ARR_SIZE] = { 'p', 'a', 'r', 'a', 'g' };
    
    const std::string output( input, ARRAY_SIZE(input) );
    std::cout << output << std::endl;
    //To check on the size 
    assert(output.length() == MAX_INPUT_ARR_SIZE);
    return 0;

}

Sunday, October 05, 2014

Clean untracked files in GIT repo

Sometimes you add some files/directory to your (local cloned) git repo directory. May be because you need them for testing or they are additional files required for reference
and it does not makes sense to add a particular directory/path in your .gitignore file. But then you want to clean those files.

git reset --hard HEAD ./<folder>
[parag@machine: Workdir] git reset --hard HEAD ./<foler>

does not work, as it does not clean with specific paths. You can do it via:


[parag@machine: Workdir] git clean -d -f

Section 80C TMT 2023(PA) – Standard Deduction amounting to a maximum of Rs 8670 under IT rule

With the recently concluded Tax filing season (which if I may draw parallel to the Christmas holiday season enjoyed by one and all), Indians...