小编Pat*_*tel的帖子

字符串长度错误

我正在使用fgets函数从stdin读取字符串,然后尝试打印字符串的长度,但是我总是第一次得到字符串的长度为1这是我的代码

#incldue<stdio.h>
#include<string.h>
int main(void)
{
   printf("\n Enter the no of test cases");
   scanf("%d",&t);
   int i,j;
   for(i=0;i<t;++i)
   {
     char song[500],val[28];
     int k=0,x=0;
     fgets(song,500,stdin);
     int len=strlen(song);
     printf("\nlen=%d",len);
   }
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

我总是得到1作为第一个测试用例的长度:/请建议我哪里出错了

c string loops

2
推荐指数
1
解决办法
404
查看次数

指向结构的指针

声明为原子数据类型(如int)时的指针就像这样工作

int a,*b=&a;

printf("\n The address of pointer b = %p",&b); //Here using & operator we get the memory location where the pointer b is stored itself

printf("\n The pointer b points to %p this memory location",b); //The will give me the value of ptr and that value is the memory address of the variable a

printf("\n The value at the memory where pointer b points is %d",*b);//Using * operator we get the value stored at the memory location hold …
Run Code Online (Sandbox Code Playgroud)

c struct pointers operators

-1
推荐指数
1
解决办法
69
查看次数

标签 统计

c ×2

loops ×1

operators ×1

pointers ×1

string ×1

struct ×1