Upper Case or Lower Case String in Linux C

There is no direct function to convert a string to upper case or lower case in Linux C. Here we collect 2 functions from internet:

#include <ctype.h>

static char* Str2Upper(char *str)  
{  
    if(str == NULL)
        return NULL;
   
    char *p = str;  
   
    while(*str)
    {  
        *str = toupper(*str);  
        str++;  
    }
   
    return p;  
}

 

static char* Str2Lower(char *str)
{
if(str == NULL)
return NULL;

char *p = str;

while(*str)
{
*str = tolower(*str);
str++;
}

return p;
}

Install Eclipse for C/C++ Windows Edition

We have a C++ project based on Linux system, so we need a good Editor but not Visual Studio since the C++ is for Linux.

And, we do not want to use Ubuntu but just use Windows 7. So we decide to download Eclipse for C/C++ Windows Edition from Eclipse official site. (Note: our Windows 7 is 64-bit so we chose Eclipse 64-bit edition)

Please know also “[Canada] University of Waterloo Computer Science Club (http)” is the server for downloading Eclipse.

After you download, unzip it and double click eclipse.exe to run, but you might see the following error message:

eclipse4c00

Then just like install Eclipse for Java, we have to install Java runtime environment or JDK. Just check our posts for Eclipse for Java installation.

OK, we install JRE.

eclipse4c01

After JRE installation, we then can continue to install Eclipse for C/C++:

eclipse4c02

Specify a work folder:

eclipse4c03

After some while for installation process, the Eclipse install successfully.

eclipse4c04

Hello World Example in Different Languages

If you are learning C, C++ or even Java, the first code example might be similar, they are all a example named Hello World.

We found a interesting article which collects all Hello World example in different languages.

For example:

In C:

#include <stdio.h>
 
int main(void)
{
  printf("Hello world\n");
  return 0;
}

In C++:

#include <iostream>
 
int main()
{
  std::cout << "Hello World!" << std::endl;
  return 0;
}

In Java:

public class HelloWorld {
   public static void main(String[] args) {
       System.out.println("Hello world!");
   }
}

Please read more in all other languages from Wikipedia

Difference between ‘struct’ and ‘typedef struct’ in C++?

Question:

In C++, is there any difference between:
struct Foo { … };
and
typedef struct { … } Foo;

Answer:

90 down vote accepted
   

In C++, there is no difference. It’s a holdover from C, in which it made a difference.

In C, there are two different namespaces of types: a namespace of struct/union/enum tag names and a namespace of typedef names. If you just said

struct Foo { … };
Foo x;

You would get a compiler error, because Foo is only defined in the tag namespace. You’d have to declare it as

struct Foo x;

Any time you want to refer to a Foo, you’d always have to call it a struct Foo. This gets annoying fast, so you can add a typedef:

struct Foo { … };
typedef struct Foo Foo;

Now both struct Foo (in the tag namespace) and just plain Foo (in the typedef namespace) both refer to the same thing, and you can freely declare objects of type Foo without the struct keyword. The construct

typedef struct Foo { … } Foo;

is just an abbreviation for the declaration and typedef. Finally,

typedef struct { … } Foo;

declares an anonymous structure and creates a typedef for it. Thus, with this construct, it doesn’t have a name in the tag namespace, only a name in the typedef namespace. This means it also can’t be forward-declared. If you want to make a forward declaration, you have to give it a name in the tag namespace.

In C++, all struct/union/enum/class declarations act like they are implicitly typedef’ed, as long as the name is not hidden by another declaration with the same name. See Michael Burr’s answer for the full details.

from Stackoverflow

A sample using union in C

This sample code is for testing some data type border value using C union. Worked on Linux OS.

#include
#include

int main(void)
{
union
{
unsigned long int lms;
unsigned short shms[2];
unsigned char  bms [4];
} myms;

myms.lms = 0;

while (1)
{

printf(“long: %ld  short: %d  byte: %d\n”, myms.lms, myms.shms[0], myms.bms[0]);
usleep(900);
myms.lms++;
}
return 0;
}