#include<stdio.h> #include<stdlib.h> #include<conio.h> void display(char *, int); int main() { char *ip; char *op[4]; int j, i=0, num=0, count[4]={0, 0, 0, 0}; printf("Enter the response of GSM Module : "); //gets(ip); scanf_s("%s",ip); printf("%s",ip); //printf("Hello"); for(i;;i++) { printf("%c",*(ip+i)); if(*(ip+i)=='"') { op[num]=ip+i+1; for(j=i+1;;j++) { printf("%c",*(ip+j)); if(*(ip+j)=='"') { count[num]=j-i-2; num+= 1; i=j; break; } } } if(*(ip+i)=='\n') break; } ///printf("ip : %d Count : %d op : %d difference : %d\n",ip, count, op, (op-ip)); printf("\nSender's Number : "); display(op[0],count[0]); printf("\nMessage Status : "); display(op[1],count[1]); printf("\n Date & Time : "); display(op[2],count[2]); printf("\nReceived Message : "); display(op[3],count[3]); _getch(); return 0; } void display(char *dip, int c) { int i; for(i=0;i<=c;i++) printf("%c",*(dip+i)); }
In this code, ip is a character pointer. Generally in C variables without initialisation is normal. But here it gives the error of uninitialised variable ip used.
I have tried to initialise ip by setting it equal to NULL, but it also gives me another error.
Earlier I have successfully compiled and run a code without initialisation and by modifying that code only, I generated this code.
Please suggest me what to do, as I can't find any problem in my code.