Hey there,

I have a simple question:

How can I read three characters by three characters from a string (character array) in C?

Thanks for your help.

here example if you wanna read 3 characters

#include <stdio.h>
#define REQUIRED 3
int main(void)
{
    char name[]="NAME";
    int i;
    for(i=0; i<REQUIRED ;i++)
        printf("%c",name[i]);
    //or if you want read full name
    for(i=0;name[i]!=0;i++)//read untill null terminator is reached
       printf("%c",name[i]);
    getchar( );
    return 0;
}

remeber it will only read it wont change to 3 characters only

This should help.

for(i=0;string[i]!='\0';)
{
for(j=0;j<3;j++,i++)
{
tempstring[i]=string[j]  /*this seperates into 3s, tweak this and you'll get necessary output each time tempstring is overwritten, write a code to avoid it */
}
}

Hey there,

I have a simple question:

How can I read three characters by three characters from a string (character array) in C?

Thanks for your help.

You can't. A string is a single dimensional array and you need an array of arrays to read 3 by 3.

You can't. A string is a single dimensional array and you need an array of arrays to read 3 by 3.

Not necessarily.

commented: Cryptic responses are not helpful. And to noobs, trying to explain what you mean will be confusing and non-helpful -4
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.