0

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.

4
Contributors
4
Replies
12
Views
8 Years
Discussion Span
Last Post by s_sridhar
0

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

0

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 */
}
}
0

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.

-1

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

Not necessarily.

Votes + Comments
Cryptic responses are not helpful. And to noobs, trying to explain what you mean will be confusing and non-helpful
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.