暂时向前移动指针

时间:2016-02-24 00:12:31

标签: c pointers

我想在我的指针中暂时向前移动,所以我不想立即使用*s++;。我怎么会在我的指针中暂时向前移动?我认为这对int x[5]; int i = 0; x[i+1];来说是件好事。

const char *buffer;
const char *s = buffer;
char a;
char b;
if(*s == '/' && *s + 1 == '*')
{
    a = *s;
    parser_comment_level++;
    *s++;
    a = *s;
    *s++;
    a = *s;
    }
if(*s == '*' && *s + 1 == '/')
{
    a = *s;
    parser_comment_level--;
    *s++;
    a = *s;
    *s++;
    a = *s;
    }
*s++;

2 个答案:

答案 0 :(得分:1)

您是否在寻找类似的内容:*(s+1)

答案 1 :(得分:0)

有三种方法:

#include <stdio.h>

const char buffer[] = "i'm a buffer's data!";

void main() {
    char character;
    const char * pbuf = buffer + 3;

    character = *(pbuf - 3);
    printf("%c\n", character);   
    // prints 'i' letter, the first char of the string

    character = pbuf[8];
    printf("%c\n", character);
    // prints 'r' letter, the 12th char of the string

    character = 8[pbuf];
    printf("%c\n", character);
    // prints 'r' letter, the 12th char of the string

}