English 中文(简体)
无法通过职能将价值纳入阵列或扼杀点
原标题:Unable to put values into either string array or string pointers via a function

我有一个200个性特征的节目,显示我分成几个部分,并试图将这些部分分成两组,或由一系列要点通过职能加以扼杀。 我可以主要成功地做到这一点,但当我通过描述特征和2个果园或点阵阵列来扼杀自己没有做的工作时。 当我印刷该功能中的2个阵列时,它显示一切都完美无缺,但当我主要印刷返回阵列时,它只印制了以下最后价值。

简化编码样本和产出如下:

void func(char *buffer, char **file_list) 
{  
  /*split buffer into segments*/  
    Strcpy((*file_list + i), segment);  
    Printf(“i = %d file_list = %s 
”,i, (*file_list + i));  /* this prints the segments perfectly*/  
}  

Main()  
{  
   Func(buffer, file_list);  
  For(i=0;i<n;i++)  
     Printf(“i= %d,split lines in main is %s
”,i,(*file_list +i));  
}  

“func”内的印刷产出是:

Segment one  
Segement two  
 ……  
Segment n  

主要产出是:

Segment n  
Segment n  
…..  
Segment n  

请在下文中更详细地说明这一职能。 我假定你不需要看到变式声明清单。

请注意,我还试图将要点作为参考,以为如果缓冲是指最初的特征阵列,那么我会指出这一点,而不是临时性的。 但公认,我对一些临时变量没有了解。

Void func(char *buffer,  char **file_list)  
{
    newline=strstr(buffer,"
");    
    while (newline != NULL  && (newline-buffer)< READ_SIZE)  
  {  
      temp_var=newline;  
      newline=strstr(newline + 1,"
");  
      if( newline !=NULL )    
      {
          strncpy((*file_list+i),temp_var,(newline-temp_var));  
          printf("i= %d, file_list is %s
",i, (*file_list+i));  
      }   
   }  
}  

Main()   
{  
    Char *buffer = (char * ) malloc(200*sizeof(char));  
    Char **file_list= blah blah ….  

   /* put 200 char string in buffer*/   

  /*file_list is still empty call func to fill it up*/     

   Func(buffer,file_list);  
   For(i=0;i<n;i++)  
      printf("i= %d, file_list is %s
",i,(*file_list+i));  
}  

职能产出:

i=0 file list is "segment one"  
i=1 file list is "segment two"  
....  
i=n file list is "segment n"  

主要产出是:

i=0 file list is "segment n"  
i=1 file list is "segment n"  
....  
i=n file list is "segment n" 
问题回答

感谢您的答复。 我发现,问题与以不正确的方式从职能中恢复数据无关,但是因为我对点人阵列使用了错误的标语。 然而,希望能很好地参考从职能中恢复数据,因为网上信息似乎相互矛盾。 例如,我不认为你需要向点人发出点名,以便参照点。 至少通过试验,我发现我能够改变点阵列的数值,而不通过点子阵列,以你通过参照通过正常变量的方式改变功能。

你们喜欢的种子只是你的一个部分,而不是全部内容。 页: 1 电话:for loop?





相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签