如何'重新声明'指向字符串的字符串指针?

时间:2018-06-02 15:10:32

标签: c string pointers

我正在使用带有一堆库的Arduino,因此它会过于聚集在一起发布整个代码。 引用字符串指针的点是:

entrada = "some lots of text written here";  //assigning value to the string
...
while (1) { 
funcao();  //calls in for a function, which can't have parameters for an unrelated problem
}

后来,在void循环中,这是主要功能:

void funcao() {
  char *texto = entrada;
  int tamanho = strlen(texto);
  int rtn_ctrl =1;
  ...
  do {
    for(int i=1; i<=tamanho; i++){  //moves every char in n to n-1
      texto[i-1] = texto[i];
    }
    texto[tamanho - rtn_ctrl] ='\0';  //null in the last position of the string
    ...
    rtn_ctrl++;
  } while (rtn_ctrl<=tamanho-(8);  //by the end of this loop, many positions of the string will be '\0';
 return 0;
}

在函数中,我将修改字符串中的值但不想丢失其原始值,因此我将其内容分配给另一个

application.config(['$routeProvider','$httpProvider', '$locationProvider', function($routeProvider, $locationProvider, $localStorage, $window, $httpProvider) {

  $httpProvider.interceptors.push('AuthInterceptors');

}]);

该函数在第一次执行时正确运行。但是,当我在主循环上再次调用它时,应该在函数上重新声明的字符串值不会重置为“entrada”。也就是说,它的所有位置仍然是'\ 0'。

0 个答案:

没有答案