473,408 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Errors in scanf and scanf_s

35
Hi all,

I am having a strange problem when I run the scanf. The following is my code:

Expand|Select|Wrap|Line Numbers
  1.   int main(int argc, char** argv){
  2.  
  3.      int result;
  4.  
  5.      char* Y = (char*)malloc(sizeof(char)*MAXLENGTH);
  6.  
  7.      printf("Enter the target DNA sequence :");
  8.      result = scanf_s("%c",&Y);
  9.      if(result == EOF){
  10.         printf("Read no character.\n");
  11.         return 1;
  12.      }
  13.  
  14.      char* X = (char*)malloc(sizeof(char)*MAXLENGTH);
  15.      printf("\nEnter the query DNA sequence :");
  16.      result = scanf_s("%c",&X);
  17.      printf("\n");
  18.      if(result == EOF){
  19.         printf("Read no character.\n");
  20.         return 1;
  21.      }
  22.  
  23.      runSW(X,Y);
  24.      CUT_EXIT(argc, argv);
  25. }
The target DNA sequence can be entered. But the program stops as soon as I enter the sequence.
Could anyone give me a hint why this happens?
Thx.
Mar 4 '08 #1
2 3141
oler1s
671 Expert 512MB
Explain to me the use of %c in your scanf call.
Mar 4 '08 #2
Hi all,

I am having a strange problem when I run the scanf. The following is my code:

Expand|Select|Wrap|Line Numbers
  1.   int main(int argc, char** argv){
  2.  
  3.      int result;
  4.  
  5.      char* Y = (char*)malloc(sizeof(char)*MAXLENGTH);
  6.  
  7.      printf("Enter the target DNA sequence :");
  8.      result = scanf_s("%c",&Y);
  9.      if(result == EOF){
  10.         printf("Read no character.\n");
  11.         return 1;
  12.      }
  13.  
  14.      char* X = (char*)malloc(sizeof(char)*MAXLENGTH);
  15.      printf("\nEnter the query DNA sequence :");
  16.      result = scanf_s("%c",&X);
  17.      printf("\n");
  18.      if(result == EOF){
  19.         printf("Read no character.\n");
  20.         return 1;
  21.      }
  22.  
  23.      runSW(X,Y);
  24.      CUT_EXIT(argc, argv);
  25. }
The target DNA sequence can be entered. But the program stops as soon as I enter the sequence.
Could anyone give me a hint why this happens?
Thx.
Is your result really EOF? Is that why you are returning? What line does your execution stop on? Have you tried running this with a debugger attached?

~mona
Mar 4 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

185
by: Martin Jørgensen | last post by:
Hi, Consider: ------------ char stringinput ..bla. bla. bla. do {
2
by: jocobunshin | last post by:
Hi there! I'm new in Turbo C... uhmm our teacher gave us a project to make a program in Turbo C. Im from the Philippines, and our project is due on tuesday, februrary 13, 2007... can anyone check my...
2
by: menyki | last post by:
error c: ......line 3: unable to open include file 'stdio.h error c: ....... line 4: unable to open include file 'stdlib.h' error c: ........line 5: unable to open include file 'time.h' error c:...
1
by: menyki | last post by:
I HV DONE ALL THE CORRECTIONS. IS ONLY THE HEADER FILE ERRORS THAT ARE STILL REMAINING.I GUESS IS FROM COMPILER, I HV DONE ALL U SAID I SHOULD DO WITH HEATHER FILE BUT STILL IS NOT WORKING.MAY BE MY...
24
by: Sharath | last post by:
Below is a link to an errata list I made for the book "Test Your C Skills" Written by Yashwant Kanetker. http://avsharath.googlepages.com/TestYourCSkillsErrata.htm Please let me know if I've...
3
by: thalinx | last post by:
Hi can ayone help me with this program, cause i dont know how to solve the compiling errors here. thanks # include<stdlib.h> # include<conio.h> # include<stdio.h> # define MAXCADENA 8 # define...
1
by: howa | last post by:
Hi, How to accept bool value from stdin, using scanf? e.g. bool b ; scanf_s("%d", &b); It will show:
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.